Class: PostRunner::PersonalRecords::RecordSet
- Inherits:
-
Object
- Object
- PostRunner::PersonalRecords::RecordSet
- Includes:
- Fit4Ruby::Converters
- Defined in:
- lib/postrunner/PersonalRecords.rb
Instance Attribute Summary collapse
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #delete_activity(activity) ⇒ Object
-
#each {|@distance| ... } ⇒ 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(sport, year) ⇒ RecordSet
constructor
A new instance of RecordSet.
- #register_result(result) ⇒ Object
- #to_html(doc) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sport, year) ⇒ RecordSet
Returns a new instance of RecordSet.
106 107 108 109 110 111 112 113 114 |
# File 'lib/postrunner/PersonalRecords.rb', line 106 def initialize(sport, year) @sport = sport @year = year @distance = nil @speed_records = {} PersonalRecords::SpeedRecordDistances[@sport].each_key do |dist| @speed_records[dist] = nil end end |
Instance Attribute Details
#year ⇒ Object (readonly)
Returns the value of attribute year.
104 105 106 |
# File 'lib/postrunner/PersonalRecords.rb', line 104 def year @year end |
Instance Method Details
#delete_activity(activity) ⇒ Object
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/postrunner/PersonalRecords.rb', line 147 def delete_activity(activity) if @distance && @distance.activity == activity @distance = nil end PersonalRecords::SpeedRecordDistances[@sport].each_key do |dist| if @speed_records[dist] && @speed_records[dist].activity == activity @speed_records[dist] = nil end end end |
#each {|@distance| ... } ⇒ Object
Iterator for all Record objects that are stored in this data structure.
167 168 169 170 171 172 |
# File 'lib/postrunner/PersonalRecords.rb', line 167 def each(&block) yield(@distance) if @distance @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.
159 160 161 162 163 164 |
# File 'lib/postrunner/PersonalRecords.rb', line 159 def empty? return false if @distance @speed_records.each_value { |r| return false if r } true end |
#register_result(result) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/postrunner/PersonalRecords.rb', line 116 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] if old_record.nil? || old_record.duration > result.duration @speed_records[result.distance] = 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.nil? || result.distance > @distance.distance @distance = result 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
180 181 182 |
# File 'lib/postrunner/PersonalRecords.rb', line 180 def to_html(doc) generate_table.to_html(doc) end |
#to_s ⇒ Object
174 175 176 177 178 |
# File 'lib/postrunner/PersonalRecords.rb', line 174 def to_s return '' if empty? generate_table.to_s + "\n" end |