Class: Biz::Configuration
- Inherits:
-
Object
- Object
- Biz::Configuration
- Defined in:
- lib/biz/configuration.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #breaks ⇒ Object
- #holidays ⇒ Object
-
#initialize {|raw| ... } ⇒ Configuration
constructor
A new instance of Configuration.
- #intervals ⇒ Object
- #shifts ⇒ Object
- #time_zone ⇒ Object
- #weekdays ⇒ Object
Constructor Details
#initialize {|raw| ... } ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 10 11 12 13 14 |
# File 'lib/biz/configuration.rb', line 6 def initialize @raw = Raw.new yield raw if block_given? Validation.perform(raw) raw.freeze end |
Instance Method Details
#&(other) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/biz/configuration.rb', line 70 def &(other) self.class.new do |config| config.hours = Interval.to_hours(intersected_intervals(other)) config.breaks = combined_breaks(other) config.holidays = [*raw.holidays, *other.raw.holidays].map(&:to_date) config.time_zone = raw.time_zone end end |
#breaks ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/biz/configuration.rb', line 38 def breaks @breaks ||= begin raw .breaks .flat_map { |date, hours| hours.map { || date_period(date, ) } } .sort .freeze end end |
#holidays ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/biz/configuration.rb', line 50 def holidays @holidays ||= begin raw .holidays .to_a .uniq .map { |date| Holiday.new(date, time_zone) } .sort .freeze end end |
#intervals ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/biz/configuration.rb', line 16 def intervals @intervals ||= begin raw .hours .flat_map { |weekday, hours| weekday_intervals(weekday, hours) } .sort .freeze end end |
#shifts ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/biz/configuration.rb', line 26 def shifts @shifts ||= begin raw .shifts .flat_map { |date, hours| hours.map { || date_period(date, ) } } .sort .freeze end end |
#time_zone ⇒ Object
62 63 64 |
# File 'lib/biz/configuration.rb', line 62 def time_zone @time_zone ||= TZInfo::TimezoneProxy.new(raw.time_zone) end |
#weekdays ⇒ Object
66 67 68 |
# File 'lib/biz/configuration.rb', line 66 def weekdays @weekdays ||= raw.hours.keys.uniq.freeze end |