class WorkLogController

Public Instance Methods

add_work_log(date, description) click to toggle source
# File lib/work_log_controller.rb, line 9
def add_work_log(date, description)
  if description.nil? || description.empty?
    raise ArgumentError, 'Description must not be empty'
  end

  WorkLogFileDao.new.save(create_work_log(date, description))
end
delete(id) click to toggle source
# File lib/work_log_controller.rb, line 25
def delete(id)
  WorkLogFileDao.new.delete(id)
end
find_by_month_and_year(month, year) click to toggle source
# File lib/work_log_controller.rb, line 29
def find_by_month_and_year(month, year)
  sort_by_date(WorkLogFileDao.new.find_by_month_and_year(month, year))
end
find_by_year(year) click to toggle source
# File lib/work_log_controller.rb, line 33
def find_by_year(year)
  sort_by_date(WorkLogFileDao.new.find_by_year(year))
end
list(date) click to toggle source
# File lib/work_log_controller.rb, line 17
def list(date)
  sort_by_date(WorkLogFileDao.new.list(parse_date(date)))
end
list_all() click to toggle source
# File lib/work_log_controller.rb, line 21
def list_all
  sort_by_date(WorkLogFileDao.new.list_all)
end

Private Instance Methods

create_work_log(date, description) click to toggle source
# File lib/work_log_controller.rb, line 39
def create_work_log(date, description)
  WorkLog.new(SecureRandom.uuid, parse_date(date), description)
end
parse_date(date) click to toggle source
# File lib/work_log_controller.rb, line 43
def parse_date(date)
  if date.nil? || date.empty? || date.downcase == 'today'
    Date.today
  elsif date.downcase == 'yesterday'
    Date.today.prev_day
  else
    Date.strptime(date, '%d/%m/%Y')
  end
end
sort_by_date(work_log_list) click to toggle source
# File lib/work_log_controller.rb, line 53
def sort_by_date(work_log_list)
  work_log_list.sort_by(&:date)
end