Class: Herodot::Configuration
- Inherits:
-
Object
- Object
- Herodot::Configuration
- Defined in:
- lib/herodot/configuration.rb
Constant Summary collapse
- CONFIG_FILE =
File.('~/.herodot.yml').freeze
- DEFAULT_CONFIGURATION =
{ 'projects_directory' => '~', 'work_times' => { 'work_start' => '9:30', 'lunch_break_start' => '13:00', 'lunch_break_end' => '13:30', 'work_end' => '18:00' } }.freeze
Instance Method Summary collapse
-
#initialize(worklog_file = '~/worklog') ⇒ Configuration
constructor
A new instance of Configuration.
- #load_configuration ⇒ Object
- #projects_directory ⇒ Object
- #save_configuration ⇒ Object
- #work_times ⇒ Object
- #worklog_file ⇒ Object
Constructor Details
#initialize(worklog_file = '~/worklog') ⇒ Configuration
Returns a new instance of Configuration.
15 16 17 18 19 20 21 22 23 |
# File 'lib/herodot/configuration.rb', line 15 def initialize(worklog_file = '~/worklog') @worklog_file = worklog_file if File.exist?(CONFIG_FILE) @config = load_configuration else @config = DEFAULT_CONFIGURATION save_configuration end end |
Instance Method Details
#load_configuration ⇒ Object
41 42 43 |
# File 'lib/herodot/configuration.rb', line 41 def load_configuration File.open(CONFIG_FILE) { |f| YAML.load(f) } end |
#projects_directory ⇒ Object
29 30 31 |
# File 'lib/herodot/configuration.rb', line 29 def projects_directory File.(@config['projects_directory']) end |
#save_configuration ⇒ Object
37 38 39 |
# File 'lib/herodot/configuration.rb', line 37 def save_configuration File.open(CONFIG_FILE, 'w') { |f| YAML.dump(@config, f) } end |
#work_times ⇒ Object
33 34 35 |
# File 'lib/herodot/configuration.rb', line 33 def work_times @config['work_times'].map { |k, v| [k.to_sym, v.split(':').map(&:to_i)] } end |
#worklog_file ⇒ Object
25 26 27 |
# File 'lib/herodot/configuration.rb', line 25 def worklog_file File.(@worklog_file) end |