Class: GPXReader::Gpx

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Gpx

read the file containing the tracks get the different information of the file get the tracks



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gpx_reader/gpx.rb', line 29

def initialize(file)
  if file.is_a?(File)
    @gpx=Nokogiri::XML(File.open(file))
  else
    @gpx=Nokogiri::XML(file)
  end
  @creator = @gpx.at_css("gpx")["creator"] rescue nil
  @time = Time.parse(@gpx.at_css("metadata time").text) rescue nil
  @tracks = []
  @gpx.css("trk").each do |trk|
     trk = Track.new(trk)
     @tracks << trk
  end
  # get name spaces
  ns = @gpx.collect_namespaces
  # Strip the leading xmlns: from each namespace key, and store in a new hash
  @namespaces= {}
  ns.each_pair do |key, value|
    @namespaces[key.sub(/^xmlns:/, '')] = value
  end
end

Instance Attribute Details

#boundariesObject

Returns the value of attribute boundaries.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def boundaries
  @boundaries
end

#creatorObject

Returns the value of attribute creator.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def creator
  @creator
end

#durationObject

Returns the value of attribute duration.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def duration
  @duration
end

#highest_pointObject

Returns the value of attribute highest_point.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def highest_point
  @highest_point
end

#lowest_pointObject

Returns the value of attribute lowest_point.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def lowest_point
  @lowest_point
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def name
  @name
end

#namespacesObject

Returns the value of attribute namespaces.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def namespaces
  @namespaces
end

#timeObject

Returns the value of attribute time.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def time
  @time
end

#tracksObject

Returns the value of attribute tracks.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def tracks
  @tracks
end

#versionObject

Returns the value of attribute version.



25
26
27
# File 'lib/gpx_reader/gpx.rb', line 25

def version
  @version
end