Class: Flyboy::Goal
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Flyboy::Goal
- Includes:
- AASM, Dorsale::Search
- Defined in:
- app/models/flyboy/goal.rb
Instance Method Summary collapse
- #create_tracking ⇒ Object
-
#initialize(*args) ⇒ Goal
constructor
A new instance of Goal.
- #no_undone_tasks? ⇒ Boolean
- #revision ⇒ Object
- #update_progress ⇒ Object
- #update_progress! ⇒ Object
- #update_version ⇒ Object
Constructor Details
#initialize(*args) ⇒ Goal
30 31 32 33 |
# File 'app/models/flyboy/goal.rb', line 30 def initialize(*args) super self.progress = 0 if progress.nil? end |
Instance Method Details
#create_tracking ⇒ Object
45 46 47 48 |
# File 'app/models/flyboy/goal.rb', line 45 def create_tracking dailycounter = Goal.where("DATE(created_at) = ?", Date.today).count + 1 self.tracking = "#{Time.now.strftime("%y%m%d")}-#{dailycounter}" end |
#no_undone_tasks? ⇒ Boolean
35 36 37 |
# File 'app/models/flyboy/goal.rb', line 35 def no_undone_tasks? tasks.where(done: false).count == 0 end |
#revision ⇒ Object
39 40 41 |
# File 'app/models/flyboy/goal.rb', line 39 def revision "#{tracking} #{version}" end |
#update_progress ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/models/flyboy/goal.rb', line 57 def update_progress if tasks.count.zero? self.progress = 0 else self.progress = tasks.sum(:progress) / tasks.count end end |
#update_progress! ⇒ Object
65 66 67 68 |
# File 'app/models/flyboy/goal.rb', line 65 def update_progress! update_progress save end |
#update_version ⇒ Object
52 53 54 55 |
# File 'app/models/flyboy/goal.rb', line 52 def update_version self.version = 0 if self.version.nil? self.version = self.version + 1 end |