Class: GpxRuby::Gpx::Track
- Inherits:
-
Object
- Object
- GpxRuby::Gpx::Track
- Defined in:
- lib/gpx_ruby/gpx/track.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#segments ⇒ Object
Returns the value of attribute segments.
-
#source ⇒ Object
Returns the value of attribute source.
-
#time ⇒ Object
Returns the value of attribute time.
-
#url ⇒ Object
Returns the value of attribute url.
-
#url_name ⇒ Object
Returns the value of attribute url_name.
Instance Method Summary collapse
- #center_of_gravity ⇒ Object
- #distance ⇒ Object
-
#initialize(a_hash) ⇒ Track
constructor
A new instance of Track.
- #points ⇒ Object
- #total_time ⇒ Object
Constructor Details
#initialize(a_hash) ⇒ Track
Returns a new instance of Track.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gpx_ruby/gpx/track.rb', line 11 def initialize(a_hash) @name = a_hash[:name] @time = a_hash[:time] @segments = a_hash[:segments] || [] @number = a_hash[:number] @source = a_hash[:source] @url = a_hash[:url] @url_name = a_hash[:url_name] @comment = a_hash[:comment] @description = a_hash[:description] end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def comment @comment end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def number @number end |
#segments ⇒ Object
Returns the value of attribute segments.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def segments @segments end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def source @source end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def time @time end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def url @url end |
#url_name ⇒ Object
Returns the value of attribute url_name.
7 8 9 |
# File 'lib/gpx_ruby/gpx/track.rb', line 7 def url_name @url_name end |
Instance Method Details
#center_of_gravity ⇒ Object
37 38 39 40 41 42 |
# File 'lib/gpx_ruby/gpx/track.rb', line 37 def center_of_gravity track_points = points len = track_points.size center = track_points.reduce(:+) center / len end |
#distance ⇒ Object
27 28 29 |
# File 'lib/gpx_ruby/gpx/track.rb', line 27 def distance @distance ||= @segments.map {|segment| segment.distance }.reduce(:+) end |
#points ⇒ Object
23 24 25 |
# File 'lib/gpx_ruby/gpx/track.rb', line 23 def points @points ||= @segments.map {|segment| segment.points }.reduce(:+) end |
#total_time ⇒ Object
31 32 33 34 35 |
# File 'lib/gpx_ruby/gpx/track.rb', line 31 def total_time start_time = @segments.first.points.first.time end_time = @segments.last.points.last.time end_time - start_time rescue 0 end |