Class: Forerunner301

Inherits:
BaseConverter show all
Defined in:
lib/converters/forerunner301.rb

Constant Summary collapse

@@device_name =
"Forerunner301"

Instance Method Summary collapse

Methods inherited from BaseConverter

converters, inherited

Instance Method Details

#convert(xml_doc) ⇒ Object



14
15
16
# File 'lib/converters/forerunner301.rb', line 14

def convert(xml_doc)
  convert_to_domain_model(xml_doc)     
end

#convert_to_domain_model(doc) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/converters/forerunner301.rb', line 18

def convert_to_domain_model(doc)
  journeys = Array.new
  doc.elements.each("//Run/") do |journey_xml|       
    journeys.push(process_journey(journey_xml))
  end
  journeys.sort
end

#process_journey(journey_xml) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/converters/forerunner301.rb', line 26

def process_journey(journey_xml)
  journey = Journey.new('Run')
  
  journey_xml.each_element("Lap/Track/Trackpoint") do |trackpoint|
    process_trackpoint(journey, trackpoint)
  end  
  
  journey
end

#process_trackpoint(journey, trackpoint) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/converters/forerunner301.rb', line 36

def process_trackpoint(journey, trackpoint)
  position = trackpoint.get_elements("Position")[0]
  
  if(position)
    time = trackpoint.get_elements("Time")[0].get_text    
    lat = position.get_elements("LatitudeDegrees")[0].get_text
    long = position.get_elements("LongitudeDegrees")[0].get_text
    alt = position.get_elements("AltitudeMeters")[0].get_text
    point = Point.new(lat.to_s.to_f, long.to_s.to_f, alt.to_s.to_f)      
    sample = Sample.new(time, point)
    journey.add_sample(sample)
  end      
end

#to_sObject



50
51
52
# File 'lib/converters/forerunner301.rb', line 50

def to_s
  @@device_name
end