Class: MonthEntryLoader
- Inherits:
-
Object
- Object
- MonthEntryLoader
- Defined in:
- lib/konkit_worklogger/month_entry.rb
Instance Method Summary collapse
- #balance_with_carry(year, month) ⇒ Object
- #calculate_balance(year, month) ⇒ Object
-
#initialize(day_loader) ⇒ MonthEntryLoader
constructor
A new instance of MonthEntryLoader.
- #load(year, month) ⇒ Object
Constructor Details
#initialize(day_loader) ⇒ MonthEntryLoader
Returns a new instance of MonthEntryLoader.
17 18 19 |
# File 'lib/konkit_worklogger/month_entry.rb', line 17 def initialize(day_loader) @day_loader = day_loader end |
Instance Method Details
#balance_with_carry(year, month) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/konkit_worklogger/month_entry.rb', line 54 def balance_with_carry(year, month) current_month_entry = load(year, month) previous_month_entry = load(year, month - 1) if previous_month_entry.days_worked != 0 current_month_entry.month_balance + balance_with_carry(year, month - 1) else current_month_entry.month_balance end end |
#calculate_balance(year, month) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/konkit_worklogger/month_entry.rb', line 47 def calculate_balance(year, month) entry = load(year, month) balance_in_sec = entry.month_balance balance_in_sec end |
#load(year, month) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/konkit_worklogger/month_entry.rb', line 21 def load(year, month) minutes_of_work = 0 days_worked = 0 month_balance = 0 day_entries = {} (1..31).each do |day| begin day_entry = @day_loader.load_from_file(year, month, day) unless day_entry.nil? time_in_day = day_entry.time_in_minutes day_entries[day] = time_in_day minutes_of_work += time_in_day days_worked += 1 month_balance += time_in_day - (8 * 60) end rescue Errno::ENOENT end end MonthEntry.new(minutes_of_work, days_worked, month_balance, day_entries) end |