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.
16 17 18 19 20 21 22 23 24 |
# File 'lib/herodot/configuration.rb', line 16 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
43 44 45 |
# File 'lib/herodot/configuration.rb', line 43 def load_configuration File.open(CONFIG_FILE) { |f| YAML.load(f) } end |
#projects_directory ⇒ Object
30 31 32 |
# File 'lib/herodot/configuration.rb', line 30 def projects_directory File.(@config['projects_directory'] || DEFAULT_CONFIGURATION['projects_directory']) end |
#save_configuration ⇒ Object
39 40 41 |
# File 'lib/herodot/configuration.rb', line 39 def save_configuration File.open(CONFIG_FILE, 'w') { |f| YAML.dump(@config, f) } end |
#work_times ⇒ Object
34 35 36 37 |
# File 'lib/herodot/configuration.rb', line 34 def work_times (@config['work_times'] || DEFAULT_CONFIGURATION['work_times']) .map { |k, v| [k.to_sym, v.split(':').map(&:to_i)] } end |
#worklog_file ⇒ Object
26 27 28 |
# File 'lib/herodot/configuration.rb', line 26 def worklog_file File.(@worklog_file) end |