Class: CollectionJSON::Template
- Defined in:
- lib/collection-json/attributes/template.rb
Instance Method Summary collapse
Methods inherited from Attribute
attribute, from_hash, nested_attributes, root_node, #to_hash, #to_json
Instance Method Details
#build(params = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/collection-json/attributes/template.rb', line 10 def build(params = {}) {'template' => Hash.new}.tap do |hash| hash['template']['data'] = data.inject([]) do |array,data| result = {'name' => data.name, 'value' => data.value} result['value'] = params[data.name] unless params[data.name].nil? result['value'] = params[data.name.to_sym] unless params[data.name.to_sym].nil? result['value'].nil? ? array : array << result end end end |