Class: ConfigurationRepository
- Inherits:
-
Object
- Object
- ConfigurationRepository
- Defined in:
- lib/configuration/configuration_repository.rb
Overview
Repository storing available configuration parameters. If no parameters are set from the user, the default values for the parameters are used.
Instance Attribute Summary collapse
-
#repository ⇒ Hash
readonly
Hash of parameters and their values.
Instance Method Summary collapse
-
#change_option(symbol, value) ⇒ Object
method to change the value of a specific symbol to a new value.
-
#check_boolean(value) ⇒ Object
private
method to check the special case for boolean parameters.
-
#check_symbol_existance(symbol) ⇒ Object
private
method to check if a given symbol exists in the options hash.
-
#check_value_class(symbol, value) ⇒ Object
private
method to check if the provided value class is the same as the value class set as the current value.
-
#default_options ⇒ Object
private
method to initialize the attribute with the specified default values.
-
#initialize(options = nil) ⇒ ConfigurationRepository
constructor
initialization.
-
#process_options(options) ⇒ Object
private
method to overwrite the default values with the provided values.
-
#raise_type_error ⇒ Object
private
method to raise a Type error if the value check fails.
Constructor Details
#initialize(options = nil) ⇒ ConfigurationRepository
initialization
14 15 16 17 |
# File 'lib/configuration/configuration_repository.rb', line 14 def initialize(=nil) () if ( != nil) end |
Instance Attribute Details
#repository ⇒ Hash (readonly)
Returns Hash of parameters and their values.
10 11 12 |
# File 'lib/configuration/configuration_repository.rb', line 10 def repository @repository end |
Instance Method Details
#change_option(symbol, value) ⇒ Object
method to change the value of a specific symbol to a new value
22 23 24 25 26 27 |
# File 'lib/configuration/configuration_repository.rb', line 22 def change_option(symbol, value) check_symbol_existance(symbol) check_value_class(symbol, value) @repository[symbol] = value end |
#check_boolean(value) ⇒ Object (private)
method to check the special case for boolean parameters
72 73 74 75 76 |
# File 'lib/configuration/configuration_repository.rb', line 72 def check_boolean(value) if (!(value.class == TrueClass || value.class == FalseClass)) raise_type_error end end |
#check_symbol_existance(symbol) ⇒ Object (private)
method to check if a given symbol exists in the options hash
50 51 52 53 54 55 |
# File 'lib/configuration/configuration_repository.rb', line 50 def check_symbol_existance(symbol) if (@repository[symbol] == nil) raise ArgumentError, ' Error [Configuration]: the provided option does not exist.'.red end end |
#check_value_class(symbol, value) ⇒ Object (private)
method to check if the provided value class is the same as the value class set as the current value
61 62 63 64 65 66 67 68 |
# File 'lib/configuration/configuration_repository.rb', line 61 def check_value_class(symbol, value) if (@repository[symbol].class == TrueClass || @repository[symbol].class == FalseClass) check_boolean(value) elsif (@repository[symbol].class != value.class) raise_type_error end end |
#default_options ⇒ Object (private)
method to initialize the attribute with the specified default values
32 33 34 35 36 37 |
# File 'lib/configuration/configuration_repository.rb', line 32 def @repository = Hash.new() @repository[:legend_extend] = false # interval output for color legend @repository[:y_time_size] = 20 # number of intervals in y for timeline @repository[:auto_scale] = false # scale visualization by terminal size end |
#process_options(options) ⇒ Object (private)
method to overwrite the default values with the provided values
41 42 43 44 45 |
# File 'lib/configuration/configuration_repository.rb', line 41 def () @repository.each_key { |key| @repository[key] = [key] if ([key]) } end |
#raise_type_error ⇒ Object (private)
method to raise a Type error if the value check fails
81 82 83 84 |
# File 'lib/configuration/configuration_repository.rb', line 81 def raise_type_error raise TypeError, ' Error [Configuration]: the type of a new value does '\ 'not fit the original type.'.red end |