Class: Hatemile::Util::Configure
- Inherits:
-
Object
- Object
- Hatemile::Util::Configure
- Defined in:
- lib/hatemile/util/configure.rb
Overview
The Configure class contains the configuration of HaTeMiLe.
Instance Method Summary collapse
-
#get_parameter(parameter) ⇒ String
Returns the value of a parameter of configuration.
-
#get_parameters ⇒ Hash
Returns the parameters of configuration.
-
#has_parameter?(parameter) ⇒ Boolean
Check that the configuration has an parameter.
-
#initialize(files_name = nil, locales = [:'en-US']) ⇒ Configure
constructor
Initializes a new object that contains the configuration of HaTeMiLe.
Constructor Details
#initialize(files_name = nil, locales = [:'en-US']) ⇒ Configure
Initializes a new object that contains the configuration of HaTeMiLe.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hatemile/util/configure.rb', line 30 def initialize(files_name = nil, locales = [:'en-US']) Hatemile::Helper.require_valid_type(files_name, Array) Hatemile::Helper.require_valid_type(files_name, Array) if files_name.nil? pattern = File.join( File.dirname(File.dirname(File.dirname(__FILE__))), 'locale', '*.yml' ) files_name = Dir.glob(pattern) end @locales = locales @parameters = {} files_name.each do |file_name| @parameters = @parameters.merge(YAML.load_file(file_name)) end end |
Instance Method Details
#get_parameter(parameter) ⇒ String
Returns the value of a parameter of configuration.
81 82 83 84 85 86 87 88 89 |
# File 'lib/hatemile/util/configure.rb', line 81 def get_parameter(parameter) @locales.each do |locale| next if @locales.last == locale value = @parameters[locale.to_s]['hatemile'].fetch(parameter, nil) return value unless value.nil? end @parameters[@locales.last.to_s]['hatemile'].fetch(parameter) end |
#get_parameters ⇒ Hash
Returns the parameters of configuration.
53 54 55 56 57 58 59 60 61 |
# File 'lib/hatemile/util/configure.rb', line 53 def get_parameters clone_parameters = {} @locales.each do |locale| clone_parameters = @parameters[locale.to_s]['hatemile'].merge( clone_parameters ) end clone_parameters end |
#has_parameter?(parameter) ⇒ Boolean
Check that the configuration has an parameter.
69 70 71 72 73 74 |
# File 'lib/hatemile/util/configure.rb', line 69 def has_parameter?(parameter) @locales.each do |locale| return true if @parameters[locale.to_s]['hatemile'].key?(parameter) end false end |