Class: FilterRename::WordsConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_rename/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ WordsConfig

Returns a new instance of WordsConfig.



32
33
34
35
36
# File 'lib/filter_rename/config.rb', line 32

def initialize(cfg)
  cfg.each do |key, value|
    instance_variable_set('@' + key.to_s, value)
  end
end

Instance Method Details

#get_words(name, section, idx = nil) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/filter_rename/config.rb', line 38

def get_words(name, section, idx = nil)
  w = instance_variable_get('@' + name.to_s)
  raise InvalidWordsGroup, name if w.nil? || name.to_s.empty?
  raise InvalidWordsSection.new(name, section) unless w.has_key? section.to_sym

  if idx.nil?
    return w[section]
  elsif w[section].class == Array
    raise InvalidWordsIndex.new(name, section, idx) unless idx < w[section].length
    return w[section][idx].to_s
  else
    return w[section].to_s
  end
end