Class: WorkingCalendar::WeekDay

Inherits:
Object
  • Object
show all
Includes:
CastHelper
Defined in:
lib/working_calendar/week_day.rb

Constant Summary

Constants included from CastHelper

CastHelper::DAY_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CastHelper

#cast_date, #cast_day_name, #cast_hours_ranges

Constructor Details

#initialize(day_name, hours_ranges) ⇒ WeekDay

Returns a new instance of WeekDay.



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

def initialize(day_name, hours_ranges)
  @day_name = cast_day_name day_name
  @hours_ranges = cast_hours_ranges hours_ranges
end

Instance Attribute Details

#day_nameObject (readonly)

Returns the value of attribute day_name.



6
7
8
# File 'lib/working_calendar/week_day.rb', line 6

def day_name
  @day_name
end

#hours_rangesObject (readonly)

Returns the value of attribute hours_ranges.



6
7
8
# File 'lib/working_calendar/week_day.rb', line 6

def hours_ranges
  @hours_ranges
end

Instance Method Details

#include?(time) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/working_calendar/week_day.rb', line 13

def include?(time)
  hms = Timing::HourMinutesSeconds.new time.hour, time.min, time.sec
  time.public_send("#{day_name}?") && hours_ranges.any? { |from, to| hms.between? from, to }
end

#to_sObject Also known as: inspect



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

def to_s
  "#{day_name.capitalize} #{hours_ranges}"
end