Class: GPX::GPX

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

Overview

Class is responsible for parsing GPX files and calculate track statistics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GPX

Returns a new instance of GPX.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/gpx/gpx.rb', line 70

def initialize(path)
	@doc = nil
	
	begin
		path = open(path)
		doc = Nokogiri::XML(path)
	rescue
		raise GPXInvalidFileException
	end
	
	# raise GPXInvalidFileException if doc.children.empty?
	
	@points = []
	@dates = []
	
	doc.search('trkpt').map do |el| 
		@dates.push Time.parse(el.at('time').text)
		@points.push GeoPoint.new(
			latitude: el['lat'].to_f,
			longitude: el['lon'].to_f,
			elevation: el.at('ele').text.to_f
		)
	end
end

Instance Attribute Details

#average_speedObject (readonly)

Returns the value of attribute average_speed.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def average_speed
  @average_speed
end

#distancesObject (readonly)

Returns the value of attribute distances.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def distances
  @distances
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def end_date
  @end_date
end

#max_speedObject (readonly)

Returns the value of attribute max_speed.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def max_speed
  @max_speed
end

#pointsObject (readonly)

Returns the value of attribute points.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def points
  @points
end

#points_countObject (readonly)

Returns the value of attribute points_count.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def points_count
  @points_count
end

#speedsObject (readonly)

Returns the value of attribute speeds.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def speeds
  @speeds
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def start_date
  @start_date
end

#timesObject (readonly)

Returns the value of attribute times.



8
9
10
# File 'lib/gpx/gpx.rb', line 8

def times
  @times
end