Class: TimeLogRobot::Toggl::Entry
- Inherits:
-
Object
- Object
- TimeLogRobot::Toggl::Entry
- Defined in:
- lib/time_log_robot/toggl/entry.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#raw_entry ⇒ Object
Returns the value of attribute raw_entry.
Instance Method Summary collapse
- #comment ⇒ Object
- #description ⇒ Object
- #duration_in_seconds ⇒ Object
- #human_readable_duration ⇒ Object
- #id ⇒ Object
-
#initialize(raw_entry) ⇒ Entry
constructor
A new instance of Entry.
- #project_name ⇒ Object
- #should_tag? ⇒ Boolean
- #start ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(raw_entry) ⇒ Entry
Returns a new instance of Entry.
6 7 8 |
# File 'lib/time_log_robot/toggl/entry.rb', line 6 def initialize(raw_entry) @raw_entry = raw_entry end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
4 5 6 |
# File 'lib/time_log_robot/toggl/entry.rb', line 4 def duration @duration end |
#raw_entry ⇒ Object
Returns the value of attribute raw_entry.
4 5 6 |
# File 'lib/time_log_robot/toggl/entry.rb', line 4 def raw_entry @raw_entry end |
Instance Method Details
#comment ⇒ Object
14 15 16 17 18 |
# File 'lib/time_log_robot/toggl/entry.rb', line 14 def comment matches = raw_entry['description'].match(/(\{(?<comment>[^\}]*)\})/) return matches['comment'] unless matches.nil? || !matches.strip.empty? description end |
#description ⇒ Object
10 11 12 |
# File 'lib/time_log_robot/toggl/entry.rb', line 10 def description raw_entry['description'] end |
#duration_in_seconds ⇒ Object
24 25 26 27 |
# File 'lib/time_log_robot/toggl/entry.rb', line 24 def duration_in_seconds # Toggl sends times in milliseconds @duration_in_seconds ||= raw_entry['dur']/1000 end |
#human_readable_duration ⇒ Object
30 31 32 33 34 35 |
# File 'lib/time_log_robot/toggl/entry.rb', line 30 def human_readable_duration total_minutes = duration_in_seconds/60 hours = total_minutes/60 remaining_minutes = total_minutes - hours * 60 "#{hours}h #{remaining_minutes}m" end |
#id ⇒ Object
37 38 39 |
# File 'lib/time_log_robot/toggl/entry.rb', line 37 def id raw_entry['id'] end |
#project_name ⇒ Object
45 46 47 |
# File 'lib/time_log_robot/toggl/entry.rb', line 45 def project_name raw_entry['project'] || '' end |
#should_tag? ⇒ Boolean
49 50 51 |
# File 'lib/time_log_robot/toggl/entry.rb', line 49 def should_tag? true end |
#start ⇒ Object
20 21 22 |
# File 'lib/time_log_robot/toggl/entry.rb', line 20 def start DateTime.strptime(raw_entry['start'], "%FT%T%:z").strftime("%FT%T.%L%z") end |
#tags ⇒ Object
41 42 43 |
# File 'lib/time_log_robot/toggl/entry.rb', line 41 def raw_entry['tags'] end |