Class: WorkingCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/working_calendar.rb,
lib/working_calendar/version.rb,
lib/working_calendar/week_day.rb,
lib/working_calendar/cast_helper.rb,
lib/working_calendar/single_date.rb

Defined Under Namespace

Modules: CastHelper Classes: SingleDate, WeekDay

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone_offset) ⇒ WorkingCalendar

Returns a new instance of WorkingCalendar.



11
12
13
14
15
16
17
# File 'lib/working_calendar.rb', line 11

def initialize(zone_offset)
  @zone_offset = Timing::ZoneOffset.parse zone_offset
  @working_week_days = []
  @working_dates = []
  @not_working_week_days = []
  @not_working_dates = []
end

Instance Attribute Details

#not_working_datesObject (readonly)

Returns the value of attribute not_working_dates.



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

def not_working_dates
  @not_working_dates
end

#not_working_week_daysObject (readonly)

Returns the value of attribute not_working_week_days.



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

def not_working_week_days
  @not_working_week_days
end

#working_datesObject (readonly)

Returns the value of attribute working_dates.



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

def working_dates
  @working_dates
end

#working_week_daysObject (readonly)

Returns the value of attribute working_week_days.



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

def working_week_days
  @working_week_days
end

#zone_offsetObject (readonly)

Returns the value of attribute zone_offset.



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

def zone_offset
  @zone_offset
end

Instance Method Details

#add_not_working_date(date, hours_ranges) ⇒ Object



31
32
33
# File 'lib/working_calendar.rb', line 31

def add_not_working_date(date, hours_ranges)
  not_working_dates << SingleDate.new(date, hours_ranges)
end

#add_not_working_week_day(day_name, hours_ranges) ⇒ Object



27
28
29
# File 'lib/working_calendar.rb', line 27

def add_not_working_week_day(day_name, hours_ranges)
  not_working_week_days << WeekDay.new(day_name, hours_ranges)
end

#add_working_date(date, hours_ranges) ⇒ Object



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

def add_working_date(date, hours_ranges)
  working_dates << SingleDate.new(date, hours_ranges)
end

#add_working_week_day(day_name, hours_ranges) ⇒ Object



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

def add_working_week_day(day_name, hours_ranges)
  working_week_days << WeekDay.new(day_name, hours_ranges)
end

#working_at?(time) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/working_calendar.rb', line 35

def working_at?(time)
  time_in_zone = Timing::TimeInZone.new(time).to_zone(zone_offset)

  (working_week_days | working_dates).any? { |e| e.include? time_in_zone } &&
  !(not_working_week_days | not_working_dates).any? { |e| e.include? time_in_zone }
end