Class: RaceCheckpointTime

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/race_checkpoint_time.rb

Instance Method Summary collapse

Instance Method Details

#elapsed_timeObject



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

#gainObject



130
131
132
# File 'app/models/race_checkpoint_time.rb', line 130

def gain
  position - previous_position
end

#intervalObject



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_secondsObject



114
115
116
# File 'app/models/race_checkpoint_time.rb', line 114

def interval_in_seconds
  read_attribute(:interval)
end

#inverted_leg_positionObject



86
87
88
# File 'app/models/race_checkpoint_time.rb', line 86

def inverted_leg_position
  race_instance.total_runners - leg_position
end

#inverted_positionObject



73
74
75
# File 'app/models/race_checkpoint_time.rb', line 73

def inverted_position
  race_instance.total_runners - position
end

#leg_positionObject



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

#positionObject



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

#previousObject



118
119
120
# File 'app/models/race_checkpoint_time.rb', line 118

def previous
  performance.time_at(checkpoint.previous) if checkpoint.previous
end

#previous_positionObject



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_secondsObject



98
99
100
# File 'app/models/race_checkpoint_time.rb', line 98

def time_in_seconds
  read_attribute(:elapsed_time)
end

#to_sObject



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