Class: PostRunner::PersonalRecords
- Inherits:
-
Object
- Object
- PostRunner::PersonalRecords
- Includes:
- Fit4Ruby::Converters
- Defined in:
- lib/postrunner/PersonalRecords.rb
Overview
The PersonalRecords class stores the various records. Records are grouped by specific year or all-time records.
Defined Under Namespace
Classes: Record, RecordSet, SportRecords
Constant Summary collapse
- SpeedRecordDistances =
List of popular distances for each sport.
{ 'cycling' => { 1000.0 => '1 km', 5000.0 => '5 km', 8000.0 => '8 km', 9000.0 => '9 km', 10000.0 => '10 km', 20000.0 => '20 km', 40000.0 => '40 km', 80000.0 => '80 km', 90000.0 => '90 km', 12000.0 => '120 km', 18000.0 => '180 km', }, 'running' => { 400.0 => '400 m', 500.0 => '500 m', 800.0 => '800 m', 1000.0 => '1 km', 1609.0 => '1 mi', 2000.0 => '2 km', 3000.0 => '3 km', 5000.0 => '5 km', 10000.0 => '10 km', 20000.0 => '20 km', 30000.0 => '30 km', 21097.5 => 'Half Marathon', 42195.0 => 'Marathon' }, 'swimming' => { 100.0 => '100 m', 300.0 => '300 m', 400.0 => '400 m', 750.0 => '750 m', 1500.0 => '1.5 km', 1930.0 => '1.2 mi', 3000.0 => '3 km', 4000.0 => '4 km', 3860.0 => '2.4 mi' }, 'walking' => { 500.0 => '500 m', 1000.0 => '1 km', 1609.0 => '1 mi', 5000.0 => '5 km', 10000.0 => '10 km', 21097.5 => 'Half Marathon', 42195.0 => 'Marathon' } }
Instance Method Summary collapse
-
#activity_records(activity) ⇒ Object
Return an Array of all the records associated with the given Activity.
- #delete_activity(activity) ⇒ Object
- #delete_all_records ⇒ Object
-
#each(&block) ⇒ Object
Iterator for all Record objects that are stored in this data structure.
-
#initialize(activities) ⇒ PersonalRecords
constructor
A new instance of PersonalRecords.
- #register_result(activity, sport, distance, duration, start_time) ⇒ Object
- #sync ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(activities) ⇒ PersonalRecords
Returns a new instance of PersonalRecords.
300 301 302 303 304 305 306 307 |
# File 'lib/postrunner/PersonalRecords.rb', line 300 def initialize(activities) @activities = activities @db_dir = activities.db_dir @records_file = File.join(@db_dir, 'records.yml') delete_all_records load_records end |
Instance Method Details
#activity_records(activity) ⇒ Object
Return an Array of all the records associated with the given Activity.
362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/postrunner/PersonalRecords.rb', line 362 def activity_records(activity) records = [] each do |record| # puts record.activity if record.activity.equal?(activity) && !records.include?(record) records << record end end records end |
#delete_activity(activity) ⇒ Object
327 328 329 |
# File 'lib/postrunner/PersonalRecords.rb', line 327 def delete_activity(activity) @sport_records.each_value { |r| r.delete_activity(activity) } end |
#delete_all_records ⇒ Object
320 321 322 323 324 325 |
# File 'lib/postrunner/PersonalRecords.rb', line 320 def delete_all_records @sport_records = {} SpeedRecordDistances.keys.each do |sport| @sport_records[sport] = SportRecords.new(sport) end end |
#each(&block) ⇒ Object
Iterator for all Record objects that are stored in this data structure.
357 358 359 |
# File 'lib/postrunner/PersonalRecords.rb', line 357 def each(&block) @sport_records.each_value { |r| r.each(&block) } end |
#register_result(activity, sport, distance, duration, start_time) ⇒ Object
309 310 311 312 313 314 315 316 317 318 |
# File 'lib/postrunner/PersonalRecords.rb', line 309 def register_result(activity, sport, distance, duration, start_time) unless @sport_records.include?(sport) Log.info "Ignoring records for activity type '#{sport}' in " + "#{activity.fit_file}" return false end result = Record.new(activity, sport, distance, duration, start_time) @sport_records[sport].register_result(result) end |
#sync ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/postrunner/PersonalRecords.rb', line 331 def sync save_records non_empty_records = @sport_records.select { |s, r| !r.empty? } max = non_empty_records.length i = 0 non_empty_records.each do |sport, record| output_file = File.join(@activities.cfg[:html_dir], "records-#{i}.html") RecordListPageView.new(@activities, record, max, i). write(output_file) i += 1 end end |
#to_s ⇒ Object
346 347 348 349 350 351 352 353 354 |
# File 'lib/postrunner/PersonalRecords.rb', line 346 def to_s str = '' @sport_records.each do |sport, record| next if record.empty? str += "Records for activity type #{sport}:\n\n#{record.to_s}" end str end |