class TimetrapToggl::Formatter
Constants
- TOGGABLE_REGEX
Attributes
config[R]
entry[R]
Public Class Methods
new(entry, config)
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 6 def initialize(entry, config) @entry = entry @config = config end
Public Instance Methods
code()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 52 def code if match = TOGGABLE_REGEX.match(entry[:note]) code = match[1].downcase end end
description()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 58 def description entry[:note].gsub("@#{code}", '').strip end
duration()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 62 def duration seconds_for_time(entry[:start], entry[:end]) end
format()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 11 def format if project && project["id"] { "description" => description, "duration" => duration, "start" => start, "pid" => project["id"], "created_with" => "timetrap-toggl", } else { error: "Project #{code} does not exist", note: entry[:note] } end end
project()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 32 def project if config.aliases[code] config.projects.find do |p| p["name"] == config.aliases[code] end else config.projects.find do |p| code == p["name"].downcase.gsub(/[^a-zA-Z\d\s]/, '').gsub(/\s+/, '-') end end end
round_in_minutes()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 48 def round_in_minutes config.round_in_minutes end
seconds_for_time(start_time, end_time)
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 66 def seconds_for_time(start_time, end_time) (end_time - start_time).to_i end
start()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 28 def start TogglV8::API.new.iso8601(entry[:start].to_datetime) end
task_id()
click to toggle source
# File lib/timetrap_toggl/formatter.rb, line 44 def task_id alias_config[:task_id] end