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.
3 4 5 |
# File 'app/models/activity.rb', line 3 def activity_type_new_title @activity_type_new_title end |
#activity_type_title ⇒ Object
Returns the value of attribute activity_type_title.
3 4 5 |
# File 'app/models/activity.rb', line 3 def activity_type_title @activity_type_title end |
#in_review ⇒ Object
Returns the value of attribute in_review.
3 4 5 |
# File 'app/models/activity.rb', line 3 def in_review @in_review end |
Class Method Details
.attribute_names ⇒ Object
Extend with virtual attributes.
174 175 176 |
# File 'app/models/activity.rb', line 174 def self.attribute_names super + %w(activity_type_title activity_type_new_title) end |
.completion_score ⇒ Object
273 274 275 276 277 278 279 |
# File 'app/models/activity.rb', line 273 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
247 248 249 |
# File 'app/models/activity.rb', line 247 def actual_accomplishment_value Values::Accomplishment.from_intensity(actual_accomplishment_intensity) end |
#actual_editable? ⇒ Boolean
193 194 195 196 197 198 199 |
# File 'app/models/activity.rb', line 193 def actual_editable? if end_time && !reviewed_and_incomplete? end_time < Time.zone.now else false end end |
#actual_pleasure_value ⇒ Object
243 244 245 |
# File 'app/models/activity.rb', line 243 def actual_pleasure_value Values::Pleasure.from_intensity(actual_pleasure_intensity) end |
#actual_ratings! ⇒ Object
188 189 190 191 |
# File 'app/models/activity.rb', line 188 def validate_actual_intensities!("accomplishment") validate_actual_intensities!("pleasure") end |
#intensity_difference(attribute) ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'app/models/activity.rb', line 263 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
215 216 217 218 219 |
# File 'app/models/activity.rb', line 215 def monitored? not_reviewed? && neither_intensity_is_rated?(:predicted) && both_intensities_rated?(:actual) end |
#planned? ⇒ Boolean
221 222 223 224 225 |
# File 'app/models/activity.rb', line 221 def planned? not_reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#predicted_accomplishment_value ⇒ Object
251 252 253 |
# File 'app/models/activity.rb', line 251 def predicted_accomplishment_value Values::Accomplishment.from_intensity(predicted_accomplishment_intensity) end |
#predicted_pleasure_value ⇒ Object
255 256 257 |
# File 'app/models/activity.rb', line 255 def predicted_pleasure_value Values::Pleasure.from_intensity(predicted_pleasure_intensity) end |
#rated? ⇒ Boolean
259 260 261 |
# File 'app/models/activity.rb', line 259 def rated? actual_pleasure_intensity || actual_accomplishment_intensity end |
#reviewed_and_complete? ⇒ Boolean
227 228 229 230 231 |
# File 'app/models/activity.rb', line 227 def reviewed_and_complete? reviewed? && both_intensities_rated?(:predicted) && both_intensities_rated?(:actual) end |
#reviewed_and_incomplete? ⇒ Boolean
233 234 235 236 237 |
# File 'app/models/activity.rb', line 233 def reviewed_and_incomplete? reviewed? && neither_intensity_is_rated?(:actual) && both_intensities_rated?(:predicted) end |
#shared_description ⇒ Object
178 179 180 |
# File 'app/models/activity.rb', line 178 def shared_description "Activity: #{activity_type.title}" end |
#status_label ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'app/models/activity.rb', line 201 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
182 183 184 185 186 |
# File 'app/models/activity.rb', line 182 def update_as_reviewed(params = {}) update( params .merge(in_review: true, is_reviewed: true)) end |
#was_recently_created? ⇒ Boolean
239 240 241 |
# File 'app/models/activity.rb', line 239 def was_recently_created? (Time.current - created_at) < 1.minute end |