Class: Biz::DayOfWeek

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/biz/day_of_week.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wday) ⇒ DayOfWeek

Returns a new instance of DayOfWeek.



20
21
22
# File 'lib/biz/day_of_week.rb', line 20

def initialize(wday)
  @wday = Integer(wday)
end

Instance Attribute Details

#wdayObject (readonly)

Returns the value of attribute wday.



18
19
20
# File 'lib/biz/day_of_week.rb', line 18

def wday
  @wday
end

Class Method Details

.allObject



10
11
12
# File 'lib/biz/day_of_week.rb', line 10

def self.all
  ALL
end

.from_symbol(symbol) ⇒ Object



14
15
16
# File 'lib/biz/day_of_week.rb', line 14

def self.from_symbol(symbol)
  ALL.fetch(SYMBOLS.index(symbol))
end

Instance Method Details

#contains?(week_minute) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/biz/day_of_week.rb', line 24

def contains?(week_minute)
  minutes.cover?(week_minute)
end

#day_minute(week_minute) ⇒ Object



44
45
46
# File 'lib/biz/day_of_week.rb', line 44

def day_minute(week_minute)
  (week_minute - 1) % Time.day_minutes + 1
end

#end_minuteObject



32
33
34
# File 'lib/biz/day_of_week.rb', line 32

def end_minute
  start_minute + Time.day_minutes
end

#minutesObject



36
37
38
# File 'lib/biz/day_of_week.rb', line 36

def minutes
  start_minute..end_minute
end

#start_minuteObject



28
29
30
# File 'lib/biz/day_of_week.rb', line 28

def start_minute
  wday * Time.day_minutes
end

#symbolObject



48
49
50
# File 'lib/biz/day_of_week.rb', line 48

def symbol
  SYMBOLS.fetch(wday)
end

#wday?(other_wday) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/biz/day_of_week.rb', line 52

def wday?(other_wday)
  wday == other_wday
end

#week_minute(day_minute) ⇒ Object



40
41
42
# File 'lib/biz/day_of_week.rb', line 40

def week_minute(day_minute)
  start_minute + day_minute
end