Class: Beggar::CurrentMonth

Inherits:
Object
  • Object
show all
Defined in:
lib/beggar/current_month.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CurrentMonth

Returns a new instance of CurrentMonth.



5
6
7
# File 'lib/beggar/current_month.rb', line 5

def initialize(options = {})
  @country = options[:country]
end

Instance Method Details

#first_dayObject



34
35
36
# File 'lib/beggar/current_month.rb', line 34

def first_day
  Date.new(year, month, 1)
end

#last_dayObject



38
39
40
# File 'lib/beggar/current_month.rb', line 38

def last_day
  first_day.next_month - 1
end

#monthObject



46
47
48
# File 'lib/beggar/current_month.rb', line 46

def month
  today.month
end

#todayObject



50
51
52
# File 'lib/beggar/current_month.rb', line 50

def today
  Date.today
end

#workday_hoursObject



17
18
19
# File 'lib/beggar/current_month.rb', line 17

def workday_hours
  workdays * 8.0
end

#workday_hours_until_todayObject



21
22
23
# File 'lib/beggar/current_month.rb', line 21

def workday_hours_until_today
  workdays_until_today * 8.0
end

#workdaysObject



9
10
11
# File 'lib/beggar/current_month.rb', line 9

def workdays
  workdays_until(last_day)
end

#workdays_progressionObject



25
26
27
# File 'lib/beggar/current_month.rb', line 25

def workdays_progression
  (workdays_until_today * 100.0 / workdays).round
end

#workdays_until(date) ⇒ Object



29
30
31
32
# File 'lib/beggar/current_month.rb', line 29

def workdays_until(date)
  (first_day..date).reject { |d|
    [0, 6].include?(d.wday) || d.holiday?(@country) }.length
end

#workdays_until_todayObject



13
14
15
# File 'lib/beggar/current_month.rb', line 13

def workdays_until_today
  workdays_until(today)
end

#yearObject



42
43
44
# File 'lib/beggar/current_month.rb', line 42

def year
  today.year
end