Class: MonthSummaryPrinter

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/konkit_worklogger/printer.rb

Instance Method Summary collapse

Methods included from Utils

#get_filename, #minutes_to_time

Constructor Details

#initialize(configuration) ⇒ MonthSummaryPrinter

Returns a new instance of MonthSummaryPrinter.



17
18
19
# File 'lib/konkit_worklogger/printer.rb', line 17

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#day_of_week(year, month, day) ⇒ Object



38
39
40
# File 'lib/konkit_worklogger/printer.rb', line 38

def day_of_week(year, month, day)
  Date.new(year, month, day).strftime('%A')[0..2]
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/konkit_worklogger/printer.rb', line 21

def print(year, month)
  day_loader = DayEntryLoader.new(@configuration)
  month_loader = MonthEntryLoader.new(day_loader)
  entry = month_loader.load(year, month)
  balance_with_carry = month_loader.balance_with_carry(year, month)

  entry.day_entries.each do |day, minutes|
    day_of_week_abbr = day_of_week(year, month, day)
    puts format('%s %s - %s', day_of_week_abbr, day, minutes_to_time(minutes))
  end

  puts 'Days worked this month: %d' % entry.days_worked
  puts format('Total count of work hours: %s/%s', minutes_to_time(entry.time_in_month), minutes_to_time(entry.days_worked * 8 * 60))
  puts 'Balance in current month: %s ' % minutes_to_time(entry.month_balance)
  puts 'Balance with carry in current month: %s ' % minutes_to_time(balance_with_carry)
end