Class: TimeLogRobot::Toggl::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/time_log_robot/toggl/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#durationObject

Returns the value of attribute duration.



4
5
6
# File 'lib/time_log_robot/toggl/entry.rb', line 4

def duration
  @duration
end

#raw_entryObject

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

#commentObject



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

#descriptionObject



10
11
12
# File 'lib/time_log_robot/toggl/entry.rb', line 10

def description
  raw_entry['description']
end

#duration_in_secondsObject



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_durationObject



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

#idObject



37
38
39
# File 'lib/time_log_robot/toggl/entry.rb', line 37

def id
  raw_entry['id']
end

#project_nameObject



45
46
47
# File 'lib/time_log_robot/toggl/entry.rb', line 45

def project_name
  raw_entry['project'] || ''
end

#should_tag?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/time_log_robot/toggl/entry.rb', line 49

def should_tag?
  true
end

#startObject



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

#tagsObject



41
42
43
# File 'lib/time_log_robot/toggl/entry.rb', line 41

def tags
  raw_entry['tags']
end