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.
184 185 186 |
# File 'app/models/activity.rb', line 184 def self.attribute_names super + %w(activity_type_title activity_type_new_title) end |
.completion_score ⇒ Object
284 285 286 287 288 289 290 |
# File 'app/models/activity.rb', line 284 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
258 259 260 |
# File 'app/models/activity.rb', line 258 def actual_accomplishment_value Values::Accomplishment.from_intensity(actual_accomplishment_intensity) end |
#actual_editable? ⇒ Boolean
204 205 206 207 208 209 210 |
# File 'app/models/activity.rb', line 204 def actual_editable? if end_time && !reviewed_and_incomplete? end_time < Time.zone.now else false end end |
#actual_pleasure_value ⇒ Object
254 255 256 |
# File 'app/models/activity.rb', line 254 def actual_pleasure_value Values::Pleasure.from_intensity(actual_pleasure_intensity) end |
#actual_ratings! ⇒ Object
199 200 201 202 |
# File 'app/models/activity.rb', line 199 def validate_actual_intensities!("accomplishment") validate_actual_intensities!("pleasure") end |
#intensity_difference(attribute) ⇒ Object
274 275 276 277 278 279 280 281 282 |
# File 'app/models/activity.rb', line 274 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
226 227 228 229 230 |
# File 'app/models/activity.rb', line 226 def monitored? not_reviewed? && neither_intensity_is_rated?(:predicted) && both_intensities_rated?(:actual) end |
#planned? ⇒ Boolean
232 233 234 235 236 |
# File 'app/models/activity.rb', line 232 def planned? not_reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#predicted_accomplishment_value ⇒ Object
262 263 264 |
# File 'app/models/activity.rb', line 262 def predicted_accomplishment_value Values::Accomplishment.from_intensity(predicted_accomplishment_intensity) end |
#predicted_pleasure_value ⇒ Object
266 267 268 |
# File 'app/models/activity.rb', line 266 def predicted_pleasure_value Values::Pleasure.from_intensity(predicted_pleasure_intensity) end |
#rated? ⇒ Boolean
270 271 272 |
# File 'app/models/activity.rb', line 270 def rated? actual_pleasure_intensity || actual_accomplishment_intensity end |
#reviewed_and_complete? ⇒ Boolean
238 239 240 241 242 |
# File 'app/models/activity.rb', line 238 def reviewed_and_complete? reviewed? && both_intensities_rated?(:predicted) && both_intensities_rated?(:actual) end |
#reviewed_and_incomplete? ⇒ Boolean
244 245 246 247 248 |
# File 'app/models/activity.rb', line 244 def reviewed_and_incomplete? reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#shared_description ⇒ Object
188 189 190 |
# File 'app/models/activity.rb', line 188 def shared_description "Activity: #{activity_type.title}" end |
#status_label ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/models/activity.rb', line 212 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
192 193 194 195 196 197 |
# File 'app/models/activity.rb', line 192 def update_as_reviewed(params = {}) update( params .merge(in_review: true, is_reviewed: true) ) end |
#was_recently_created? ⇒ Boolean
250 251 252 |
# File 'app/models/activity.rb', line 250 def was_recently_created? (Time.current - created_at) < 1.minute end |