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.



2217
2218
2219
# File 'lib/amrita2/template.rb', line 2217

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



2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
# File 'lib/amrita2/template.rb', line 2221

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