class TimetrapHarvest::Formatter

Constants

HARVESTABLE_REGEX

Attributes

config[R]
entry[R]

Public Class Methods

new(entry, config) click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 6
def initialize(entry, config)
  @entry  = entry
  @config = config
end

Public Instance Methods

alias_config() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 36
def alias_config
  config.alias_config(code)
end
code() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 44
def code
  if match = HARVESTABLE_REGEX.match(entry[:note])
    code = match[1]
  end
end
format() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 11
def format
  if alias_config && entry[:end]
    { notes:      entry[:note],
      hours:      hours_for_time(entry[:start], entry[:end]),
      project_id: project_id.to_i,
      task_id:    task_id.to_i,
      spent_at:   entry[:start].strftime('%Y%m%d')
    }
  elsif !entry[:end]
    { error: 'Entry not ended yet', note: entry[:note] }
  elsif code
    { error: 'Missing task alias config', note: entry[:note] }
  else
    { error: 'No task alias provided', note: entry[:note] }
  end
end
hours_for_time(start_time, end_time) click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 50
def hours_for_time(start_time, end_time)
  minutes = (end_time - start_time) / 60
  rounded = round(minutes)
  hours   = (rounded / 60)
end
project_id() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 28
def project_id
  alias_config[:project_id]
end
round(value, nearest = round_in_minutes) click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 56
def round(value, nearest = round_in_minutes)
  (value % nearest).zero? ? value : (value + nearest) - (value % nearest)
end
round_in_minutes() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 40
def round_in_minutes
  config.round_in_minutes
end
task_id() click to toggle source
# File lib/timetrap_harvest/formatter.rb, line 32
def task_id
  alias_config[:task_id]
end