Class: WorkingCalendar::SingleDate

Inherits:
Object
  • Object
show all
Includes:
CastHelper
Defined in:
lib/working_calendar/single_date.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(date, hours_ranges) ⇒ SingleDate

Returns a new instance of SingleDate.



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

def initialize(date, hours_ranges)
  @date = cast_date date
  @hours_ranges = cast_hours_ranges hours_ranges
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#hours_rangesObject (readonly)

Returns the value of attribute hours_ranges.



6
7
8
# File 'lib/working_calendar/single_date.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/single_date.rb', line 13

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

#to_sObject Also known as: inspect



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

def to_s
  "#{date.iso8601} #{hours_ranges}"
end