Class: PostRunner::PersonalRecords::RecordSet
- Inherits:
-
PEROBS::Object
- Object
- PEROBS::Object
- PostRunner::PersonalRecords::RecordSet
- Includes:
- Fit4Ruby::Converters
- Defined in:
- lib/postrunner/PersonalRecords.rb
Instance Method Summary collapse
- #delete_activity(activity) ⇒ Object
-
#each {|@distance_record| ... } ⇒ Object
Iterator for all Record objects that are stored in this data structure.
-
#empty? ⇒ Boolean
Return true if no Record is stored in this RecordSet object.
-
#initialize(p, sport, year) ⇒ RecordSet
constructor
A new instance of RecordSet.
- #register_result(result) ⇒ Object
- #to_html(doc) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(p, sport, year) ⇒ RecordSet
Returns a new instance of RecordSet.
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/postrunner/PersonalRecords.rb', line 128 def initialize(p, sport, year) super(p) self.sport = sport self.year = year self.distance_record = nil self.speed_records = @store.new(PEROBS::Hash) if sport PersonalRecords::SpeedRecordDistances[sport].each_key do |dist| @speed_records[dist.to_s] = nil end end end |
Instance Method Details
#delete_activity(activity) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/postrunner/PersonalRecords.rb', line 175 def delete_activity(activity) record_deleted = false if @distance_record && @distance_record.activity == activity self.distance_record = nil record_deleted = true end PersonalRecords::SpeedRecordDistances[@sport].each_key do |dist| dist = dist.to_s if @speed_records[dist] && @speed_records[dist].activity == activity @speed_records[dist] = nil record_deleted = true end end record_deleted end |
#each {|@distance_record| ... } ⇒ Object
Iterator for all Record objects that are stored in this data structure.
201 202 203 204 205 206 |
# File 'lib/postrunner/PersonalRecords.rb', line 201 def each(&block) yield(@distance_record) if @distance_record @speed_records.each_value do |record| yield(record) if record end end |
#empty? ⇒ Boolean
Return true if no Record is stored in this RecordSet object.
193 194 195 196 197 198 |
# File 'lib/postrunner/PersonalRecords.rb', line 193 def empty? return false if @distance_record @speed_records.each_value { |r| return false if r } true end |
#register_result(result) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/postrunner/PersonalRecords.rb', line 142 def register_result(result) if result.duration # We have a potential speed record for a known distance. unless PersonalRecords::SpeedRecordDistances[@sport]. include?(result.distance) Log.fatal "Unknown record distance #{result.distance}" end old_record = @speed_records[result.distance.to_s] if old_record.nil? || old_record.duration > result.duration @speed_records[result.distance.to_s] = @store.new(Record, result) Log.info "New #{@year ? @year.to_s : 'all-time'} " + "#{result.sport} speed record for " + "#{PersonalRecords::SpeedRecordDistances[@sport][ result.distance]}: " + "#{secsToHMS(result.duration)}" return true end else # We have a potential distance record. if @distance_record.nil? || @distance_record.distance < result.distance self.distance_record = @store.new(Record, result) raise RuntimeError if @distance_record.is_a?(String) Log.info "New #{@year ? @year.to_s : 'all-time'} " + "#{result.sport} distance record: #{result.distance} m" return true end end false end |
#to_html(doc) ⇒ Object
214 215 216 |
# File 'lib/postrunner/PersonalRecords.rb', line 214 def to_html(doc) generate_table.to_html(doc) end |
#to_s ⇒ Object
208 209 210 211 212 |
# File 'lib/postrunner/PersonalRecords.rb', line 208 def to_s return '' if empty? generate_table.to_s + "\n" end |