Class: Session
Instance Attribute Summary collapse
-
#handles ⇒ Object
readonly
Returns the value of attribute handles.
-
#laps ⇒ Object
readonly
Returns the value of attribute laps.
-
#projection_origin ⇒ Object
readonly
Returns the value of attribute projection_origin.
-
#route ⇒ Object
Returns the value of attribute route.
-
#session_info ⇒ Object
readonly
Returns the value of attribute session_info.
-
#straight_line_distance ⇒ Object
readonly
Returns the value of attribute straight_line_distance.
Class Method Summary collapse
Instance Method Summary collapse
- #calculate ⇒ Object
- #calculate_laps ⇒ Object
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #parse_data(data, tag_data_length) ⇒ Object
Constructor Details
Instance Attribute Details
#handles ⇒ Object (readonly)
Returns the value of attribute handles.
4 5 6 |
# File 'lib/session.rb', line 4 def handles @handles end |
#laps ⇒ Object (readonly)
Returns the value of attribute laps.
4 5 6 |
# File 'lib/session.rb', line 4 def laps @laps end |
#projection_origin ⇒ Object (readonly)
Returns the value of attribute projection_origin.
4 5 6 |
# File 'lib/session.rb', line 4 def projection_origin @projection_origin end |
#route ⇒ Object
Returns the value of attribute route.
3 4 5 |
# File 'lib/session.rb', line 3 def route @route end |
#session_info ⇒ Object (readonly)
Returns the value of attribute session_info.
4 5 6 |
# File 'lib/session.rb', line 4 def session_info @session_info end |
#straight_line_distance ⇒ Object (readonly)
Returns the value of attribute straight_line_distance.
4 5 6 |
# File 'lib/session.rb', line 4 def straight_line_distance @straight_line_distance end |
Class Method Details
.read_session(data, tag_data_length) ⇒ Object
25 26 27 |
# File 'lib/session.rb', line 25 def self.read_session(data, tag_data_length) new.parse_data(data, tag_data_length) end |
.read_sessions(data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/session.rb', line 8 def self.read_sessions(data) sessions = [] session_count = BinData::Uint32le.read(data) LOGGER.debug "reading #{session_count} sessions" session_count.times do |i| tag = TagDataExtractor.read(data) LOGGER.debug "in session #{i}, tag is #{tag} and is #{tag.data_length} bytes long" if TAGS[tag.tag] == :session sessions << read_session(data, tag.data_length) end end sessions end |
Instance Method Details
#calculate ⇒ Object
36 37 38 39 40 |
# File 'lib/session.rb', line 36 def calculate LOGGER.debug("starting to calculate shit for #{self.inspect}") route.calculate_parameters calculate_laps end |
#calculate_laps ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/session.rb', line 42 def calculate_laps last_distance, last_lap = 0, nil @laps.each do |lap| pl = route.parameterized_location_from_time(lap.time) lap.position = route.position_from_parameterized_location(pl) distance = route.distance_from_parameterized_location(pl) if lap.is_of_type?(:lap, :stop) lap.distance = distance - last_distance if last_lap lap.straight_line_distance = lap.position.distance_to(last_lap.position) else lap.straight_line_distance = 0 end @straight_line_distance += lap.straight_line_distance end last_distance = distance last_lap = lap end LOGGER.debug("Laps after calculation: #{@laps.inspect}") end |
#parse_data(data, tag_data_length) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/session.rb', line 67 def parse_data(data, tag_data_length) start_pos = data.pos while data.pos < (start_pos + tag_data_length) tag = TagDataExtractor.read(data) LOGGER.debug "tag is #{tag}, #{tag.data_length} bytes" send("set_#{TAGS[tag.tag]}", data) end self end |