Sha256: 365fc0c707806f397e4df4a4ae509139ed2499613c02adfed1fa5bc66f60e7b3
Contents?: true
Size: 1.96 KB
Versions: 6
Compression:
Stored size: 1.96 KB
Contents
#-- # Copyright (c) 2006 Doug Fales # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ module GPX # A common base class which provides a useful initializer method to many # class in the GPX library. class Base # This initializer can take an XML::Node and scrape out any text # elements with the names given in the "text_elements" array. Each # element found underneath "parent" with a name in "text_elements" causes # an attribute to be initialized on the instance. This means you don't # have to pick out individual text elements in each initializer of each # class (Route, TrackPoint, Track, etc). Just pass an array of possible # attributes to this method. def instantiate_with_text_elements(parent, text_elements) text_elements.each do |el| child_xpath = "#{el}" unless parent.at(child_xpath).nil? val = parent.at(child_xpath).inner_text self.send("#{el}=", val) end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems
Version | Path |
---|---|
gpx-0.9.0 | lib/gpx/gpx.rb |
gpx-0.8.3 | lib/gpx/gpx.rb |
gpx-0.8.2 | lib/gpx/gpx.rb |
gpx-0.8.1 | lib/gpx/gpx.rb |
andrewhao-gpx-0.8 | lib/gpx/gpx.rb |
andrewhao-gpx-0.7 | lib/gpx/gpx.rb |