Class: GPX::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gpx/gpx.rb

Overview

A common base class which provides a useful initializer method to many class in the GPX library.

Direct Known Subclasses

Bounds, GPXFile, Point, Route, Segment, Track

Instance Method Summary collapse

Instance Method Details

#instantiate_with_text_elements(parent, text_elements) ⇒ Object

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.



34
35
36
37
38
39
40
41
42
43
# File 'lib/gpx/gpx.rb', line 34

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