class Haora::DayRenderer

Public Instance Methods

render(day) click to toggle source
# File lib/haora/renderer.rb, line 19
def render(day)
  raise 'none' if day.tasks.empty?
  %W(#{rendered_date_of(day)} #{rendered(day.tasks)} #{rendered_total(day)})
    .join("\n")
end

Private Instance Methods

rendered(tasks) click to toggle source
# File lib/haora/renderer.rb, line 33
def rendered(tasks)
  tasks
    .map { |task| rendered_task(task, tasks[tasks.index(task) + 1]) }
    .join("\n")
end
rendered_date_of(day) click to toggle source
# File lib/haora/renderer.rb, line 27
def rendered_date_of(day)
  date = day.date.strftime('%a %d.%m.%Y')
  date << ' (today)' if day.date == Day.today
  date
end
rendered_project_total(name, duration) click to toggle source
# File lib/haora/renderer.rb, line 47
def rendered_project_total(name, duration)
  total = format('%s =', name[0..12])
  format('%s %5.2f', total.rjust(15), duration.hours)
end
rendered_task(task, next_task) click to toggle source
# File lib/haora/renderer.rb, line 52
def rendered_task(task, next_task)
  timespan = rendered_timespan(task.start, task.stop)
  duration = rendered_duration(task.duration.hours)
  output = rendered_task_info(task, timespan, duration)
  with_rendered_gap(task, next_task, output)
end
rendered_task_info(task, timespan, duration) click to toggle source
# File lib/haora/renderer.rb, line 59
def rendered_task_info(task, timespan, duration)
  if task.project.noname?
    output = format('%s = %s  %s',
                    timespan, duration, task.text)
  else
    output = format('%s = %s  %s: %s',
                    timespan, duration, task.project.name, task.text)
  end
  output
end
rendered_total(day) click to toggle source
# File lib/haora/renderer.rb, line 39
def rendered_total(day)
  day
    .project_names
    .collect { |name| rendered_project_total(name, day.duration(of_project: name)) }
    .push('        Total = %5.2f' % day.hours)
    .join("\n")
end
with_rendered_gap(task, next_task, output) click to toggle source
# File lib/haora/renderer.rb, line 70
def with_rendered_gap(task, next_task, output)
  unless next_task.nil?
    gap = task.gap(to_next: next_task)
    output << format("\n     %dm", gap.minutes) unless gap.minutes.zero?
  end
  output
end