Class: Morfo::Builder
- Inherits:
-
Object
- Object
- Morfo::Builder
- Defined in:
- lib/morfo/builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(definitions) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(definitions) ⇒ Builder
Returns a new instance of Builder.
3 4 5 |
# File 'lib/morfo/builder.rb', line 3 def initialize(definitions) @definitions = definitions end |
Instance Method Details
#build ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/morfo/builder.rb', line 7 def build # WTF??? `definitions` is not accessible inside class # so this javascript technique is necesseray tmp_definitions = definitions.map { |h| Morfo::Tools::ExtendedHash.symbolize_keys(h) } Class.new(Morfo::Base) do tmp_definitions.each do |definition| f = field(*definition[:field]) if definition[:from] f = f.from(*definition[:from]) end if definition[:calculated] base_hash = Morfo::Tools::BaseKeys.new(definition[:calculated]).build f = f.calculated { |r| definition[:calculated] % base_hash.merge(Morfo::Tools::FlattenHashKeys.new(r).flatten) } end if definition[:transformed] f = f.transformed { |v| definition[:transformed] % {value: v} } end end end end |