Class: GpxRuby::Gpx::Track

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

Defined Under Namespace

Classes: Point, Segment

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commentObject

Returns the value of attribute comment.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def comment
  @comment
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def description
  @description
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def name
  @name
end

#numberObject

Returns the value of attribute number.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def number
  @number
end

#segmentsObject

Returns the value of attribute segments.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def segments
  @segments
end

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def source
  @source
end

#timeObject

Returns the value of attribute time.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def time
  @time
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/gpx_ruby/gpx/track.rb', line 7

def url
  @url
end

#url_nameObject

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_gravityObject



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

#distanceObject



27
28
29
# File 'lib/gpx_ruby/gpx/track.rb', line 27

def distance
  @distance ||= @segments.map {|segment| segment.distance }.reduce(:+)
end

#pointsObject



23
24
25
# File 'lib/gpx_ruby/gpx/track.rb', line 23

def points
  @points ||= @segments.map {|segment| segment.points }.reduce(:+)
end

#total_timeObject



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