Class: Amrita2::Filters::ToHash

Inherits:
Base show all
Includes:
Util::OptionSupport
Defined in:
lib/amrita2/template.rb

Instance Attribute Summary

Attributes included from Util::OptionSupport

#opt

Attributes inherited from Base

#next_

Instance Method Summary collapse

Methods included from Util::OptionSupport

#[], #method_missing, #parse_opt

Methods inherited from Base

filter_method, inherited, #parse_filter_a, #|

Constructor Details

#initialize(key) ⇒ ToHash

Returns a new instance of ToHash.



2322
2323
2324
# File 'lib/amrita2/template.rb', line 2322

def initialize(key)
  @key = key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amrita2::Util::OptionSupport

Instance Method Details

#value_filter_code(de, cg, value) ⇒ Object



2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
# File 'lib/amrita2/template.rb', line 2326

def value_filter_code(de, cg, value)
  case @key
  when Symbol
    cg.code("$_ = { #{@key.inspect} => $_ }")
  when Hash
    cg.code("$_ = { ")
    @key.each do |k,v|
      cg.code(" #{k.inspect} => $_.amrita_value(#{v.inspect}),")
    end
    cg.code("}")
  end

  super
end