Class: Qipowl::Mappers::Mapper
Overview
Operates +mapping+ for loaded +YAML+ rules files.
- For top level sections, each section name
should have the corresponding method within Mapping class;
default is
[:includes]which is processed with #includes method which is simply loads rules from the respective file
Mapping may be loaded from YAML file, as well as be merged
against other YAML file, hash or Ruler instance.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(input = nil) ⇒ Mapper
constructor
A new instance of Mapper.
-
#load_yaml(input) ⇒ Object
private
FIXME Make file search more flexible!!!.
- #merge!(input) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(input = nil) ⇒ Mapper
Returns a new instance of Mapper.
22 23 24 25 |
# File 'lib/qipowl/core/mapper.rb', line 22 def initialize input = nil @hash = {} merge!(input) unless input.nil? end |
Instance Method Details
#load_yaml(input) ⇒ Object (private)
FIXME Make file search more flexible!!!
44 45 46 47 48 |
# File 'lib/qipowl/core/mapper.rb', line 44 def load_yaml input IO === input ? YAML.load_stream(input) : YAML.load_file("#{Qipowl.bowlers_dir}/#{input.downcase}.yaml") end |
#merge!(input) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/qipowl/core/mapper.rb', line 29 def merge! input input = load_yaml(input) if input.is_one_of?(String, IO) raise ArgumentError.new "Invalid map for merge in Mapper" \ unless input.respond_to? :to_hash incs = input.delete(:includes) @entities_dirty = true @hash.rmerge!(input.to_hash) incs.each { |inc| merge! inc } rescue NoMethodError end |
#to_hash ⇒ Object
26 27 28 |
# File 'lib/qipowl/core/mapper.rb', line 26 def to_hash @hash end |