class Hatemile::Util::Configure
The Configure
class contains the configuration of HaTeMiLe.
Public Class Methods
new(files_name = nil, locales = [:'en-US'])
click to toggle source
Initializes a new object that contains the configuration of HaTeMiLe.
@param files_name [Array<String>] The path of files. @param locales [Array<Symbol>] The locales.
# 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
Public Instance Methods
get_parameter(parameter)
click to toggle source
Returns the value of a parameter of configuration.
@param parameter [String] The parameter. @return [String] The value of the parameter.
# 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()
click to toggle source
Returns the parameters of configuration.
@return [Hash] The parameters of configuration.
# 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)
click to toggle source
Check that the configuration has an parameter.
@param parameter [String] The parameter. @return [Boolean] True if the configuration has the parameter or false
if the configuration not has the parameter.
# 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