Class: PostRunner::PersonalRecords
- Inherits:
-
Object
- Object
- PostRunner::PersonalRecords
- Includes:
- Fit4Ruby::Converters
- Defined in:
- lib/postrunner/PersonalRecords.rb
Defined Under Namespace
Classes: Record, RecordSet, SportRecords
Constant Summary collapse
- SpeedRecordDistances =
{ 'cycling' => { 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' => { 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' => { 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.
289 290 291 292 293 294 295 296 |
# File 'lib/postrunner/PersonalRecords.rb', line 289 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.
350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/postrunner/PersonalRecords.rb', line 350 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
316 317 318 |
# File 'lib/postrunner/PersonalRecords.rb', line 316 def delete_activity(activity) @sport_records.each_value { |r| r.delete_activity(activity) } end |
#delete_all_records ⇒ Object
309 310 311 312 313 314 |
# File 'lib/postrunner/PersonalRecords.rb', line 309 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.
345 346 347 |
# File 'lib/postrunner/PersonalRecords.rb', line 345 def each(&block) @sport_records.each_value { |r| r.each(&block) } end |
#register_result(activity, sport, distance, duration, start_time) ⇒ Object
298 299 300 301 302 303 304 305 306 307 |
# File 'lib/postrunner/PersonalRecords.rb', line 298 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
320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/postrunner/PersonalRecords.rb', line 320 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) end end |
#to_s ⇒ Object
334 335 336 337 338 339 340 341 342 |
# File 'lib/postrunner/PersonalRecords.rb', line 334 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 |