Class: WorkingHours::Config
- Inherits:
-
Object
- Object
- WorkingHours::Config
- Defined in:
- lib/working_hours/config.rb
Constant Summary collapse
- TIME_FORMAT =
/\A([0-1][0-9]|2[0-3]):([0-5][0-9])\z/- DAYS_OF_WEEK =
[:sun, :mon, :tue, :wed, :thu, :fri, :sat]
Class Method Summary collapse
- .holidays ⇒ Object
- .holidays=(val) ⇒ Object
-
.precompiled ⇒ Object
Returns an optimized for computing version.
- .reset! ⇒ Object
- .time_zone ⇒ Object
- .time_zone=(val) ⇒ Object
- .working_hours ⇒ Object
- .working_hours=(val) ⇒ Object
Class Method Details
.holidays ⇒ Object
23 24 25 |
# File 'lib/working_hours/config.rb', line 23 def holidays config[:holidays] end |
.holidays=(val) ⇒ Object
27 28 29 30 31 |
# File 'lib/working_hours/config.rb', line 27 def holidays=(val) validate_holidays! val config[:holidays] = val config.delete :precompiled end |
.precompiled ⇒ Object
Returns an optimized for computing version
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/working_hours/config.rb', line 34 def precompiled config_hash = [config[:working_hours], config[:holidays], config[:time_zone]].hash if config_hash != config[:config_hash] config[:config_hash] = config_hash config.delete :precompiled end config[:precompiled] ||= begin compiled = {working_hours: []} working_hours.each do |day, hours| compiled[:working_hours][DAYS_OF_WEEK.index(day)] = {} hours.each do |start, finish| compiled[:working_hours][DAYS_OF_WEEK.index(day)][compile_time(start)] = compile_time(finish) end end compiled[:holidays] = Set.new(holidays) compiled[:time_zone] = time_zone compiled end end |
.reset! ⇒ Object
65 66 67 |
# File 'lib/working_hours/config.rb', line 65 def reset! Thread.current[:working_hours] = default_config end |
.time_zone ⇒ Object
55 56 57 |
# File 'lib/working_hours/config.rb', line 55 def time_zone config[:time_zone] end |
.time_zone=(val) ⇒ Object
59 60 61 62 63 |
# File 'lib/working_hours/config.rb', line 59 def time_zone=(val) zone = validate_time_zone! val config[:time_zone] = zone config.delete :precompiled end |
.working_hours ⇒ Object
13 14 15 |
# File 'lib/working_hours/config.rb', line 13 def working_hours config[:working_hours] end |
.working_hours=(val) ⇒ Object
17 18 19 20 21 |
# File 'lib/working_hours/config.rb', line 17 def working_hours=(val) validate_working_hours! val config[:working_hours] = val config.delete :precompiled end |