Class: TomatoHarvest::TimeEntry
- Inherits:
-
Object
- Object
- TomatoHarvest::TimeEntry
- Defined in:
- lib/tomatoharvest/time_entry.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#date ⇒ Object
Date for task (today), formatted properly for tracker.
-
#initialize(options = {}) ⇒ TimeEntry
constructor
A new instance of TimeEntry.
-
#log(seconds) ⇒ Object
Persist time entry to Harvest tracker.
-
#notes ⇒ Object
Notes to send to tracker.
-
#project ⇒ Object
Harvest project with name matching options.
-
#seconds_to_hours(seconds) ⇒ Object
Convert seconds into hours.
-
#task ⇒ Object
Harvest task with name matching options.
-
#test ⇒ Object
Check that the project and task were found on Harvest.
Constructor Details
#initialize(options = {}) ⇒ TimeEntry
Returns a new instance of TimeEntry.
19 20 21 |
# File 'lib/tomatoharvest/time_entry.rb', line 19 def initialize( = {}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/tomatoharvest/time_entry.rb', line 7 def @options end |
Class Method Details
.build_and_test(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/tomatoharvest/time_entry.rb', line 9 def self.build_and_test( = {}) required = ["domain", "username", "password", "project", "task", "name"].to_set keys = .keys.to_set if required.subset?(keys) new().tap do |entry| entry.test end end end |
Instance Method Details
#date ⇒ Object
Date for task (today), formatted properly for tracker
70 71 72 |
# File 'lib/tomatoharvest/time_entry.rb', line 70 def date Date.today end |
#log(seconds) ⇒ Object
Persist time entry to Harvest tracker
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tomatoharvest/time_entry.rb', line 34 def log(seconds) hours = seconds_to_hours(seconds) return if hours == 0 = { notes: notes, hours: hours, spent_at: date, project_id: project.id, task_id: task.id } existing_entry = time_api.all.find do |entry| entry.notes == self.notes end if existing_entry existing_entry.hours += hours existing_entry.spent_at = date time_api.update(existing_entry) else entry = Harvest::TimeEntry.new() time_api.create(entry) end end |
#notes ⇒ Object
Notes to send to tracker
63 64 65 |
# File 'lib/tomatoharvest/time_entry.rb', line 63 def notes ["name"] end |
#project ⇒ Object
Harvest project with name matching options
86 87 88 89 90 |
# File 'lib/tomatoharvest/time_entry.rb', line 86 def project time_api.trackable_projects.find do |project| project.name == ["project"] end end |
#seconds_to_hours(seconds) ⇒ Object
Convert seconds into hours
77 78 79 80 81 |
# File 'lib/tomatoharvest/time_entry.rb', line 77 def seconds_to_hours(seconds) minutes = (seconds / 60.0) unrounded = (minutes / 60.0) (unrounded * 100).ceil / 100.0 end |
#task ⇒ Object
Harvest task with name matching options
95 96 97 98 99 |
# File 'lib/tomatoharvest/time_entry.rb', line 95 def task project.tasks.find do |task| task.name == ["task"] end end |
#test ⇒ Object
Check that the project and task were found on Harvest
26 27 28 29 |
# File 'lib/tomatoharvest/time_entry.rb', line 26 def test raise "Couldn't find project" unless project raise "Couldn't find task type" unless task end |