Class: GPX::Gpx
- Inherits:
-
Object
- Object
- GPX::Gpx
- Defined in:
- lib/gpx_kml/gpx.rb
Overview
Docu
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#file_name ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#link ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#name ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#points ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#points_length ⇒ Object
readonly
access in readonly to the quantity of points/routes/tracks in the gpx.
-
#routes ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#routes_length ⇒ Object
readonly
access in readonly to the quantity of points/routes/tracks in the gpx.
-
#tracks ⇒ Object
readonly
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx.
-
#tracks_length ⇒ Object
readonly
access in readonly to the quantity of points/routes/tracks in the gpx.
Instance Method Summary collapse
- #_name ⇒ Object
- #description ⇒ Object
- #gpx? ⇒ Boolean
-
#initialize(file_path) ⇒ Gpx
constructor
A new instance of Gpx.
- #points? ⇒ Boolean
- #routes? ⇒ Boolean
- #tracks? ⇒ Boolean
-
#valid? ⇒ Boolean
For a gpx file to be valid it must only have a waypoint, a route or a track.
Constructor Details
#initialize(file_path) ⇒ Gpx
Returns a new instance of Gpx.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gpx_kml/gpx.rb', line 12 def initialize(file_path) return unless correct_path?(file_path) && (File.size(file_path) < 10_000_000) @gpx = Nokogiri::XML(File.open(file_path)) return unless valid? @file_name = File.basename(file_path) @name = _name @author = @gpx.xpath('/xmlns:gpx/xmlns:metadata/xmlns:author/xmlns:name/text()').to_s @link = @gpx.xpath('/xmlns:gpx/xmlns:metadata/xmlns:link/@href').to_s @tracks = _tracks if tracks? @routes = _routes if routes? @points = _points if points? @points_length = _points_length @routes_length = _routes_length @tracks_length = _tracks_length end |
Instance Attribute Details
#author ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def @author end |
#file_name ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def file_name @file_name end |
#link ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def link @link end |
#name ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def name @name end |
#points ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def points @points end |
#points_length ⇒ Object (readonly)
access in readonly to the quantity of points/routes/tracks in the gpx
34 35 36 |
# File 'lib/gpx_kml/gpx.rb', line 34 def points_length @points_length end |
#routes ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def routes @routes end |
#routes_length ⇒ Object (readonly)
access in readonly to the quantity of points/routes/tracks in the gpx
34 35 36 |
# File 'lib/gpx_kml/gpx.rb', line 34 def routes_length @routes_length end |
#tracks ⇒ Object (readonly)
used in development of the gem, could be useful going forward to add functionalities attr_reader :gpx
31 32 33 |
# File 'lib/gpx_kml/gpx.rb', line 31 def tracks @tracks end |
#tracks_length ⇒ Object (readonly)
access in readonly to the quantity of points/routes/tracks in the gpx
34 35 36 |
# File 'lib/gpx_kml/gpx.rb', line 34 def tracks_length @tracks_length end |
Instance Method Details
#_name ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gpx_kml/gpx.rb', line 63 def _name if valid? name = @gpx.xpath('/xmlns:gpx/xmlns:metadata/xmlns:name/text()').to_s return alt_name if name.empty? return name end puts 'return empty string' '' end |
#description ⇒ Object
74 75 76 77 78 |
# File 'lib/gpx_kml/gpx.rb', line 74 def description return @gpx.xpath('//xmlns:metadata/xmlns:desc/text()').to_s if valid? '' end |
#gpx? ⇒ Boolean
36 37 38 |
# File 'lib/gpx_kml/gpx.rb', line 36 def gpx? !@gpx.nil? && !@gpx.xpath('/xmlns:gpx').empty? end |
#points? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/gpx_kml/gpx.rb', line 57 def points? return true unless @gpx.xpath('//xmlns:wpt').empty? false end |
#routes? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/gpx_kml/gpx.rb', line 45 def routes? return true unless @gpx.xpath('//xmlns:rte').empty? false end |
#tracks? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/gpx_kml/gpx.rb', line 51 def tracks? return true unless @gpx.xpath('//xmlns:trk').empty? false end |
#valid? ⇒ Boolean
For a gpx file to be valid it must only have a waypoint, a route or a track
41 42 43 |
# File 'lib/gpx_kml/gpx.rb', line 41 def valid? gpx? && (tracks? || routes? || points?) end |