Class: Hillpace::Import::Tcx::TcxParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hillpace/import/tcx/tcx_parser.rb

Overview

Parser for TCX files (see en.wikipedia.org/wiki/Training_Center_XML).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tcx_content) ⇒ TcxParser

Initializes a TcxParser object.

Parameters:

  • tcx_content (string)

    The content of a TCX file.



10
11
12
13
14
# File 'lib/hillpace/import/tcx/tcx_parser.rb', line 10

def initialize(tcx_content)
  @document = Nokogiri::XML tcx_content
  @kalman_filter = KalmanFilter.new
  @srtm = GeoElevation::Srtm.new
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'lib/hillpace/import/tcx/tcx_parser.rb', line 6

def document
  @document
end

Class Method Details

.from_file(tcx_path) ⇒ TcxParser

Creates a new TcxParser object from a TCX file path.

Parameters:

  • tcx_path (string)

    The path of the file to be parsed.

Returns:



19
20
21
# File 'lib/hillpace/import/tcx/tcx_parser.rb', line 19

def self.from_file(tcx_path)
  new File.open tcx_path
end

.from_url(tcx_url) ⇒ TcxParser

Creates a new TcxParser object from a TCX file URL.

Parameters:

  • tcx_url (string)

    The URL of the file to be parsed.

Returns:



26
27
28
# File 'lib/hillpace/import/tcx/tcx_parser.rb', line 26

def self.from_url(tcx_url)
  new open tcx_url
end

Instance Method Details

#parseRoute

Parses a TCX document. Looks for route nodes inside the document and parses them.

Returns:



33
34
35
36
37
38
39
# File 'lib/hillpace/import/tcx/tcx_parser.rb', line 33

def parse
  routes = Array.new
  document.search('Activity').each do |route_node|
    routes << parse_route(route_node)
  end
  routes
end