Class: Activity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activity
- Defined in:
- app/models/activity.rb
Overview
Represents a real-world activity of a participant.
Direct Known Subclasses
Constant Summary collapse
- PLEASURABLE_CUTOFF =
6
- ACCOMPLISHED_CUTOFF =
6
Instance Attribute Summary collapse
-
#activity_type_new_title ⇒ Object
Returns the value of attribute activity_type_new_title.
-
#activity_type_title ⇒ Object
Returns the value of attribute activity_type_title.
-
#in_review ⇒ Object
Returns the value of attribute in_review.
Class Method Summary collapse
-
.attribute_names ⇒ Object
Extend with virtual attributes.
- .completion_score ⇒ Object
Instance Method Summary collapse
- #actual_accomplishment_value ⇒ Object
- #actual_editable? ⇒ Boolean
- #actual_pleasure_value ⇒ Object
- #actual_ratings! ⇒ Object
- #intensity_difference(attribute) ⇒ Object
- #monitored? ⇒ Boolean
- #planned? ⇒ Boolean
- #predicted_accomplishment_value ⇒ Object
- #predicted_pleasure_value ⇒ Object
- #rated? ⇒ Boolean
- #reviewed_and_complete? ⇒ Boolean
- #reviewed_and_incomplete? ⇒ Boolean
- #shared_description ⇒ Object
- #status_label ⇒ Object
- #update_as_reviewed(params = {}) ⇒ Object
- #was_recently_created? ⇒ Boolean
Instance Attribute Details
#activity_type_new_title ⇒ Object
Returns the value of attribute activity_type_new_title.
4 5 6 |
# File 'app/models/activity.rb', line 4 def activity_type_new_title @activity_type_new_title end |
#activity_type_title ⇒ Object
Returns the value of attribute activity_type_title.
4 5 6 |
# File 'app/models/activity.rb', line 4 def activity_type_title @activity_type_title end |
#in_review ⇒ Object
Returns the value of attribute in_review.
4 5 6 |
# File 'app/models/activity.rb', line 4 def in_review @in_review end |
Class Method Details
.attribute_names ⇒ Object
Extend with virtual attributes.
190 191 192 |
# File 'app/models/activity.rb', line 190 def self.attribute_names super + %w(activity_type_title activity_type_new_title) end |
.completion_score ⇒ Object
290 291 292 293 294 295 296 |
# File 'app/models/activity.rb', line 290 def self.completion_score if reviewed_and_complete.count > 0 (reviewed_and_complete.count * 100 / count).round else 0 end end |
Instance Method Details
#actual_accomplishment_value ⇒ Object
264 265 266 |
# File 'app/models/activity.rb', line 264 def actual_accomplishment_value Values::Accomplishment.from_intensity(actual_accomplishment_intensity) end |
#actual_editable? ⇒ Boolean
210 211 212 213 214 215 216 |
# File 'app/models/activity.rb', line 210 def actual_editable? if end_time && !reviewed_and_incomplete? end_time < Time.zone.now else false end end |
#actual_pleasure_value ⇒ Object
260 261 262 |
# File 'app/models/activity.rb', line 260 def actual_pleasure_value Values::Pleasure.from_intensity(actual_pleasure_intensity) end |
#actual_ratings! ⇒ Object
205 206 207 208 |
# File 'app/models/activity.rb', line 205 def validate_actual_intensities!("accomplishment") validate_actual_intensities!("pleasure") end |
#intensity_difference(attribute) ⇒ Object
280 281 282 283 284 285 286 287 288 |
# File 'app/models/activity.rb', line 280 def intensity_difference(attribute) actual_intensity = send("actual_#{attribute}_intensity") predicted_intensity = send("predicted_#{attribute}_intensity") if actual_intensity && predicted_intensity (actual_intensity - predicted_intensity).abs else "N/A" end end |
#monitored? ⇒ Boolean
232 233 234 235 236 |
# File 'app/models/activity.rb', line 232 def monitored? not_reviewed? && neither_intensity_is_rated?(:predicted) && both_intensities_rated?(:actual) end |
#planned? ⇒ Boolean
238 239 240 241 242 |
# File 'app/models/activity.rb', line 238 def planned? not_reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#predicted_accomplishment_value ⇒ Object
268 269 270 |
# File 'app/models/activity.rb', line 268 def predicted_accomplishment_value Values::Accomplishment.from_intensity(predicted_accomplishment_intensity) end |
#predicted_pleasure_value ⇒ Object
272 273 274 |
# File 'app/models/activity.rb', line 272 def predicted_pleasure_value Values::Pleasure.from_intensity(predicted_pleasure_intensity) end |
#rated? ⇒ Boolean
276 277 278 |
# File 'app/models/activity.rb', line 276 def rated? actual_pleasure_intensity || actual_accomplishment_intensity end |
#reviewed_and_complete? ⇒ Boolean
244 245 246 247 248 |
# File 'app/models/activity.rb', line 244 def reviewed_and_complete? reviewed? && both_intensities_rated?(:predicted) && both_intensities_rated?(:actual) end |
#reviewed_and_incomplete? ⇒ Boolean
250 251 252 253 254 |
# File 'app/models/activity.rb', line 250 def reviewed_and_incomplete? reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#shared_description ⇒ Object
194 195 196 |
# File 'app/models/activity.rb', line 194 def shared_description "Activity: #{activity_type.title}" end |
#status_label ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/models/activity.rb', line 218 def status_label if monitored? "Monitored" elsif planned? "Planned" elsif reviewed_and_complete? "Reviewed & Completed" elsif reviewed_and_incomplete? "Reviewed and did not complete" else "N/A" end end |
#update_as_reviewed(params = {}) ⇒ Object
198 199 200 201 202 203 |
# File 'app/models/activity.rb', line 198 def update_as_reviewed(params = {}) update( params .merge(in_review: true, is_reviewed: true) ) end |
#was_recently_created? ⇒ Boolean
256 257 258 |
# File 'app/models/activity.rb', line 256 def was_recently_created? (Time.current - created_at) < 1.minute end |