Class: Configuration::ShiftConfiguration
- Inherits:
-
Configuration
- Object
- Configuration
- Configuration::ShiftConfiguration
- Defined in:
- lib/configuration/shift_configuration.rb
Overview
Configuration for credentials.
Instance Attribute Summary
Attributes inherited from Configuration
Instance Method Summary collapse
-
#shift_duration ⇒ Int
Shift duration in hours.
-
#shift_end ⇒ String
Read shift end.
-
#shift_start ⇒ String
Read shift start.
-
#update_shift_end(shift_end) ⇒ Object
Update shift end time in configuration file.
-
#update_shift_start(shift_start) ⇒ Object
Update shift start in configuration file.
- #validate_saved_shift_end ⇒ Object
- #validate_saved_shift_start ⇒ Object
Methods inherited from Configuration
Constructor Details
This class inherits a constructor from Configuration::Configuration
Instance Method Details
#shift_duration ⇒ Int
Shift duration in hours.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/configuration/shift_configuration.rb', line 88 def shift_duration duration = Utilities.time_diff_hours(shift_start, shift_end) if duration < 1 || duration > 24 raise LogworkException::InvalidShiftHoursDuration.new, "Unable to calculate your shift hours. Configuration values shift_start and/or shift_end are invalid." end duration end |
#shift_end ⇒ String
Read shift end.
58 59 60 61 62 63 64 65 66 |
# File 'lib/configuration/shift_configuration.rb', line 58 def shift_end validate_saved_shift_end shift_end = data[:shift][:end] unless Utilities.valid_time?(shift_end) raise LogworkException::InvalidTime.new, "Invalid end time formats in '#{manager.configuration_path}'." end data[:shift][:end] end |
#shift_start ⇒ String
Read shift start.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/configuration/shift_configuration.rb', line 27 def shift_start validate_saved_shift_start shift_start = data[:shift][:start] unless Utilities.valid_time?(shift_start) raise LogworkException::InvalidTime.new, "Invalid shift start time format in '#{manager.configuration_path}'." end data[:shift][:start] end |
#update_shift_end(shift_end) ⇒ Object
Update shift end time in configuration file.
76 77 78 79 80 81 82 83 |
# File 'lib/configuration/shift_configuration.rb', line 76 def update_shift_end(shift_end) raise LogworkException::InvalidTime.new, "Invalid end time format." unless Utilities.valid_time?(shift_end) shift = data[:shift] || {} shift[:end] = shift_end data[:shift] = shift manager.save_configuration end |
#update_shift_start(shift_start) ⇒ Object
Update shift start in configuration file.
46 47 48 49 50 51 52 53 |
# File 'lib/configuration/shift_configuration.rb', line 46 def update_shift_start(shift_start) raise LogworkException::InvalidTime.new, "Invalid start time format." unless Utilities.valid_time?(shift_start) shift = data[:shift] || {} shift[:start] = shift_start data[:shift] = shift manager.save_configuration end |
#validate_saved_shift_end ⇒ Object
68 69 70 71 72 73 |
# File 'lib/configuration/shift_configuration.rb', line 68 def validate_saved_shift_end return if !data[:shift].nil? && !data[:shift][:end].nil? raise LogworkException::ConfigurationValueNotFound.new, "Cannot read shift end time from configuration file at '#{manager.configuration_path}'." end |
#validate_saved_shift_start ⇒ Object
38 39 40 41 42 43 |
# File 'lib/configuration/shift_configuration.rb', line 38 def validate_saved_shift_start return if !data[:shift].nil? && !data[:shift][:start].nil? raise LogworkException::ConfigurationValueNotFound.new, "Cannot read shift start time from configuration file at '#{manager.configuration_path}'." end |