Class: RaceCheckpointTime
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RaceCheckpointTime
- Defined in:
- app/models/race_checkpoint_time.rb
Instance Method Summary collapse
- #elapsed_time ⇒ Object
- #elapsed_time=(time) ⇒ Object
- #gain ⇒ Object
- #interval ⇒ Object
- #interval_in_seconds ⇒ Object
- #inverted_leg_position ⇒ Object
- #inverted_position ⇒ Object
- #leg_position ⇒ Object
- #position ⇒ Object
- #previous ⇒ Object
- #previous_position ⇒ Object
- #time_in_seconds ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#elapsed_time ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/models/race_checkpoint_time.rb', line 90 def elapsed_time if s = read_attribute(:elapsed_time) s.to_timecode else "" end end |
#elapsed_time=(time) ⇒ Object
102 103 104 |
# File 'app/models/race_checkpoint_time.rb', line 102 def elapsed_time=(time) write_attribute(:elapsed_time, time.seconds) # numbers will pass through unchanged. strings will be timecode-parsed end |
#gain ⇒ Object
130 131 132 |
# File 'app/models/race_checkpoint_time.rb', line 130 def gain position - previous_position end |
#interval ⇒ Object
106 107 108 109 110 111 112 |
# File 'app/models/race_checkpoint_time.rb', line 106 def interval if s = read_attribute(:interval) s.to_timecode else "" end end |
#interval_in_seconds ⇒ Object
114 115 116 |
# File 'app/models/race_checkpoint_time.rb', line 114 def interval_in_seconds read_attribute(:interval) end |
#inverted_leg_position ⇒ Object
86 87 88 |
# File 'app/models/race_checkpoint_time.rb', line 86 def inverted_leg_position race_instance.total_runners - leg_position end |
#inverted_position ⇒ Object
73 74 75 |
# File 'app/models/race_checkpoint_time.rb', line 73 def inverted_position race_instance.total_runners - position end |
#leg_position ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'app/models/race_checkpoint_time.rb', line 77 def leg_position if !previous position elsif interval && interval.seconds > 0 faster = self.class.in(race_instance).at_checkpoint(checkpoint).quicker_than(interval.seconds) faster.length + 1 end end |
#position ⇒ Object
68 69 70 71 |
# File 'app/models/race_checkpoint_time.rb', line 68 def position faster = self.class.in(race_instance).at_checkpoint(checkpoint).ahead_of(elapsed_time.seconds) faster.length + 1 end |
#previous ⇒ Object
118 119 120 |
# File 'app/models/race_checkpoint_time.rb', line 118 def previous performance.time_at(checkpoint.previous) if checkpoint.previous end |
#previous_position ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/models/race_checkpoint_time.rb', line 122 def previous_position if previous previous.position else 1 end end |
#time_in_seconds ⇒ Object
98 99 100 |
# File 'app/models/race_checkpoint_time.rb', line 98 def time_in_seconds read_attribute(:elapsed_time) end |
#to_s ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/models/race_checkpoint_time.rb', line 59 def to_s time = read_attribute(:elapsed_time) if time && time != 0 time.to_timecode else "" end end |