Class: CollectionJSON::TemplateBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/collection-json/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ TemplateBuilder

Returns a new instance of TemplateBuilder.



97
98
99
# File 'lib/collection-json/builder.rb', line 97

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



95
96
97
# File 'lib/collection-json/builder.rb', line 95

def data
  @data
end

Instance Method Details

#add_data(name, value = '', prompt = '') ⇒ Object



101
102
103
104
105
106
# File 'lib/collection-json/builder.rb', line 101

def add_data(name, value = '', prompt = '')
  data << Data.from_hash({'name' => name}).tap do |data|
    data.merge!({'value' => value}) if value != ''
    data.merge!({'prompt' => prompt}) if prompt != ''
  end
end