Class: Biz::DayOfWeek
- Inherits:
-
Object
- Object
- Biz::DayOfWeek
- Includes:
- Comparable
- Defined in:
- lib/biz/day_of_week.rb
Instance Attribute Summary collapse
-
#wday ⇒ Object
readonly
Returns the value of attribute wday.
Class Method Summary collapse
Instance Method Summary collapse
- #contains?(week_minute) ⇒ Boolean
- #day_minute(week_minute) ⇒ Object
- #end_minute ⇒ Object
-
#initialize(wday) ⇒ DayOfWeek
constructor
A new instance of DayOfWeek.
- #minutes ⇒ Object
- #start_minute ⇒ Object
- #symbol ⇒ Object
- #wday?(other_wday) ⇒ Boolean
- #week_minute(day_minute) ⇒ Object
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
#wday ⇒ Object (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
.all ⇒ Object
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
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_minute ⇒ Object
32 33 34 |
# File 'lib/biz/day_of_week.rb', line 32 def end_minute start_minute + Time.day_minutes end |
#minutes ⇒ Object
36 37 38 |
# File 'lib/biz/day_of_week.rb', line 36 def minutes start_minute..end_minute end |
#start_minute ⇒ Object
28 29 30 |
# File 'lib/biz/day_of_week.rb', line 28 def start_minute wday * Time.day_minutes end |
#symbol ⇒ Object
48 49 50 |
# File 'lib/biz/day_of_week.rb', line 48 def symbol SYMBOLS.fetch(wday) end |
#wday?(other_wday) ⇒ 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 |