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_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(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.
116 117 118 119 120 121 122 123 124 |
# File 'lib/postrunner/PersonalRecords.rb', line 116 def initialize(sport, year) @sport = sport @year = year @distance_record = 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.
114 115 116 |
# File 'lib/postrunner/PersonalRecords.rb', line 114 def year @year end |
Instance Method Details
#delete_activity(activity) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/postrunner/PersonalRecords.rb', line 158 def delete_activity(activity) if @distance_record && @distance_record.activity == activity @distance_record = 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_record| ... } ⇒ Object
Iterator for all Record objects that are stored in this data structure.
178 179 180 181 182 183 |
# File 'lib/postrunner/PersonalRecords.rb', line 178 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.
170 171 172 173 174 175 |
# File 'lib/postrunner/PersonalRecords.rb', line 170 def empty? return false if @distance_record @speed_records.each_value { |r| return false if r } true end |
#register_result(result) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/postrunner/PersonalRecords.rb', line 126 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_record.nil? || @distance_record.distance < result.distance @distance_record = 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
191 192 193 |
# File 'lib/postrunner/PersonalRecords.rb', line 191 def to_html(doc) generate_table.to_html(doc) end |
#to_s ⇒ Object
185 186 187 188 189 |
# File 'lib/postrunner/PersonalRecords.rb', line 185 def to_s return '' if empty? generate_table.to_s + "\n" end |