Class: PostRunner::PersonalRecords::SportRecords
- Inherits:
-
PEROBS::Object
- Object
- PEROBS::Object
- PostRunner::PersonalRecords::SportRecords
- Defined in:
- lib/postrunner/PersonalRecords.rb
Instance Method Summary collapse
- #delete_activity(activity) ⇒ Object
-
#each(&block) ⇒ Object
Iterator for all Record objects that are stored in this data structure.
-
#empty? ⇒ Boolean
Return true if no record is stored in this SportRecords object.
-
#initialize(p, sport) ⇒ SportRecords
constructor
A new instance of SportRecords.
- #register_result(result) ⇒ Object
- #to_html(doc) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(p, sport) ⇒ SportRecords
Returns a new instance of SportRecords.
251 252 253 254 255 256 257 |
# File 'lib/postrunner/PersonalRecords.rb', line 251 def initialize(p, sport) super(p) self.sport = sport self.all_time = @store.new(RecordSet, sport, nil) self.yearly = @store.new(PEROBS::Hash) end |
Instance Method Details
#delete_activity(activity) ⇒ Object
271 272 273 274 275 276 277 278 |
# File 'lib/postrunner/PersonalRecords.rb', line 271 def delete_activity(activity) record_deleted = false ([ @all_time ] + @yearly.values).each do |r| record_deleted = true if r.delete_activity(activity) end record_deleted end |
#each(&block) ⇒ Object
Iterator for all Record objects that are stored in this data structure.
289 290 291 292 293 |
# File 'lib/postrunner/PersonalRecords.rb', line 289 def each(&block) records = @yearly.values records << @all_time if @all_time records.each { |r| r.each(&block) } end |
#empty? ⇒ Boolean
Return true if no record is stored in this SportRecords object.
281 282 283 284 285 286 |
# File 'lib/postrunner/PersonalRecords.rb', line 281 def empty? return false unless @all_time.empty? @yearly.each_value { |r| return false unless r.empty? } true end |
#register_result(result) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/postrunner/PersonalRecords.rb', line 259 def register_result(result) year = result.start_time.year.to_s unless @yearly[year] @yearly[year] = @store.new(RecordSet, @sport, year) end new_at = @all_time.register_result(result) new_yr = @yearly[year].register_result(result) new_at || new_yr end |
#to_html(doc) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/postrunner/PersonalRecords.rb', line 308 def to_html(doc) return nil if empty? doc.div { doc.h3('All-time records') @all_time.to_html(doc) @yearly.values.sort do |r1, r2| r2.year.to_i <=> r1.year.to_i end.each do |record| unless record.empty? doc.h3("Records of #{record.year}") record.to_html(doc) end end } end |
#to_s ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/postrunner/PersonalRecords.rb', line 295 def to_s return '' if empty? str = "All-time records:\n\n#{@all_time.to_s}" unless @all_time.empty? @yearly.values.sort{ |r1, r2| r2.year <=> r1.year }.each do |record| unless record.empty? str += "Records of #{record.year}:\n\n#{record.to_s}" end end str end |