Class: Weekend::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/Weekend/base.rb

Class Method Summary collapse

Class Method Details

.filter_weekdays(start_date, end_date) ⇒ Object

filter weekdays



9
10
11
# File 'lib/Weekend/base.rb', line 9

def filter_weekdays start_date, end_date
  result(start_date,end_date,[0,6])
end

.filter_weekends(start_date, end_date) ⇒ Object

Filtering weekends



4
5
6
# File 'lib/Weekend/base.rb', line 4

def filter_weekends start_date, end_date
  result(start_date,end_date,[1,2,3,4,5])
end

.no_of_weekends(start_date, end_date) ⇒ Object

no of weekends



19
20
21
# File 'lib/Weekend/base.rb', line 19

def no_of_weekends start_date, end_date
  filter_weekdays(start_date,end_date).count
end

.no_of_working_days(start_date, end_date) ⇒ Object

total working days(except weekends)



14
15
16
# File 'lib/Weekend/base.rb', line 14

def no_of_working_days start_date, end_date
  filter_weekends(start_date,end_date).count
end

.result(start_date, end_date, arr_of_days) ⇒ Object



23
24
25
# File 'lib/Weekend/base.rb', line 23

def result start_date, end_date, arr_of_days
  ((start_date.to_date)..(end_date.to_date)).to_a.select {|k| arr_of_days.include?(k.wday)}
end