A couple of fixes to make the library comply with the different attribute names

possible on the bounds element.

Formerly, a bounds element with a minlat or minLat attribute (instead of
min_lat) would not be properly parsed.  Now all three styles of attribute name
are accepted.
master
Doug Fales 2006-11-28 15:35:25 +00:00
parent 48053d44c4
commit 931a10cd17
2 changed files with 17 additions and 8 deletions

View File

@ -45,10 +45,10 @@ module GPX
def to_xml def to_xml
bnd = REXML::Element.new('bounds') bnd = REXML::Element.new('bounds')
bnd.attributes['min_lat'] = min_lat bnd.attributes['minlat'] = min_lat
bnd.attributes['min_lon'] = min_lon bnd.attributes['minlon'] = min_lon
bnd.attributes['max_lat'] = max_lat bnd.attributes['maxlat'] = max_lat
bnd.attributes['max_lon'] = max_lon bnd.attributes['maxlon'] = max_lon
bnd bnd
end end

View File

@ -53,10 +53,10 @@ module GPX
bounds_element = (XPath.match(@xml, "/gpx/metadata/bounds").first rescue nil) bounds_element = (XPath.match(@xml, "/gpx/metadata/bounds").first rescue nil)
if bounds_element if bounds_element
@bounds.min_lat = bounds_element.attributes["min_lat"].to_f @bounds.min_lat = get_bounds_attr_value(bounds_element, %w{ min_lat minlat minLat })
@bounds.min_lon = bounds_element.attributes["min_lon"].to_f @bounds.min_lon = get_bounds_attr_value(bounds_element, %w{ min_lon minlon minLon})
@bounds.max_lat = bounds_element.attributes["max_lat"].to_f @bounds.max_lat = get_bounds_attr_value(bounds_element, %w{ max_lat maxlat maxLat})
@bounds.max_lon = bounds_element.attributes["max_lon"].to_f @bounds.max_lon = get_bounds_attr_value(bounds_element, %w{ max_lon maxlon maxLon})
else else
get_bounds = true get_bounds = true
end end
@ -82,6 +82,15 @@ module GPX
end end
end end
def get_bounds_attr_value(el, possible_names)
result = nil
possible_names.each do |name|
result = el.attributes[name]
break unless result.nil?
end
return (result.to_f rescue nil)
end
# Returns the distance, in kilometers, meters, or miles, of all of the # Returns the distance, in kilometers, meters, or miles, of all of the
# tracks and segments contained in this GPXFile. # tracks and segments contained in this GPXFile.
def distance(opts = { :units => 'kilometers' }) def distance(opts = { :units => 'kilometers' })