Class: Hourglass::Activity
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Hourglass::Activity
- Defined in:
- lib/hourglass/activity.rb
Class Method Summary collapse
Instance Method Summary collapse
- #changes ⇒ Object
- #duration ⇒ Object
- #duration_in_words ⇒ Object
- #ended_at_hm ⇒ Object
- #ended_at_hm=(value) ⇒ Object
- #ended_at_mdy ⇒ Object
- #ended_at_mdy=(value) ⇒ Object
- #name_with_project ⇒ Object
- #name_with_project=(value) ⇒ Object
- #running=(value) ⇒ Object
- #running? ⇒ Boolean
- #started_at_date ⇒ Object
- #started_at_hm ⇒ Object
- #started_at_hm=(value) ⇒ Object
- #started_at_mdy ⇒ Object
- #started_at_mdy=(value) ⇒ Object
- #tag_names ⇒ Object
- #tag_names=(value) ⇒ Object
Class Method Details
.stop_current_activities ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/hourglass/activity.rb', line 47 def self.stop_current_activities current.update(:ended_at => Time.now) ids = sub_minute.select_map(:id) if !ids.empty? db[:activities_tags].filter(:activity_id => ids).delete sub_minute.delete end end |
Instance Method Details
#changes ⇒ Object
167 168 169 |
# File 'lib/hourglass/activity.rb', line 167 def changes @changes || {} end |
#duration ⇒ Object
102 103 104 |
# File 'lib/hourglass/activity.rb', line 102 def duration (ended_at ? ended_at - started_at : Time.now - started_at).floor end |
#duration_in_words ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/hourglass/activity.rb', line 106 def duration_in_words total_minutes = duration / 60 if total_minutes == 0 "0min" else minutes = total_minutes % 60 total_hours = total_minutes / 60 hours = total_hours % 24 days = total_hours / 24 strings = [] strings << "#{days}d" if days > 0 strings << "#{hours}h" if hours > 0 strings << "#{minutes}min" if minutes > 0 strings.join(" ") end end |
#ended_at_hm ⇒ Object
93 94 95 |
# File 'lib/hourglass/activity.rb', line 93 def ended_at_hm ended_at ? ended_at.strftime("%H:%M") : "" end |
#ended_at_hm=(value) ⇒ Object
97 98 99 100 |
# File 'lib/hourglass/activity.rb', line 97 def ended_at_hm=(value) modified! @ended_at_hm = value end |
#ended_at_mdy ⇒ Object
84 85 86 |
# File 'lib/hourglass/activity.rb', line 84 def ended_at_mdy ended_at ? ended_at.strftime("%m/%d/%Y") : "" end |
#ended_at_mdy=(value) ⇒ Object
88 89 90 91 |
# File 'lib/hourglass/activity.rb', line 88 def ended_at_mdy=(value) modified! @ended_at_mdy = value end |
#name_with_project ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/hourglass/activity.rb', line 145 def name_with_project if project "#{name}@#{project.name}" else name end end |
#name_with_project=(value) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/hourglass/activity.rb', line 153 def name_with_project=(value) activity_name, project_name = value ? value.strip.split("@", 2) : [nil, nil] self.name = activity_name if !project_name.nil? && !project_name.empty? project = Project.filter(:name => project_name).first if project.nil? self.project_attributes = {:name => project_name} else self.project = project end end end |
#running=(value) ⇒ Object
56 57 58 59 |
# File 'lib/hourglass/activity.rb', line 56 def running=(value) modified! @running = value end |
#running? ⇒ Boolean
124 125 126 127 128 129 130 |
# File 'lib/hourglass/activity.rb', line 124 def running? if new? @running else ended_at.nil? end end |
#started_at_date ⇒ Object
61 62 63 64 |
# File 'lib/hourglass/activity.rb', line 61 def started_at_date t = started_at Date.new(t.year, t.month, t.day) end |
#started_at_hm ⇒ Object
75 76 77 |
# File 'lib/hourglass/activity.rb', line 75 def started_at_hm started_at ? started_at.strftime("%H:%M") : "" end |
#started_at_hm=(value) ⇒ Object
79 80 81 82 |
# File 'lib/hourglass/activity.rb', line 79 def started_at_hm=(value) modified! @started_at_hm = value end |
#started_at_mdy ⇒ Object
66 67 68 |
# File 'lib/hourglass/activity.rb', line 66 def started_at_mdy started_at ? started_at.strftime("%m/%d/%Y") : "" end |
#started_at_mdy=(value) ⇒ Object
70 71 72 73 |
# File 'lib/hourglass/activity.rb', line 70 def started_at_mdy=(value) modified! @started_at_mdy = value end |
#tag_names ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/hourglass/activity.rb', line 132 def tag_names if @tag_names @tag_names else new? ? "" : .select_map(:name).join(", ") end end |
#tag_names=(value) ⇒ Object
140 141 142 143 |
# File 'lib/hourglass/activity.rb', line 140 def tag_names=(value) modified! @tag_names = value end |