Class: Prismic::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/prismic/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, name, fields, form_method, rel, enctype, action) ⇒ Form

Returns a new instance of Form.



6
7
8
9
10
11
12
13
14
# File 'lib/prismic/form.rb', line 6

def initialize(api, name, fields, form_method, rel, enctype, action)
  @api = api
  @name = name
  @fields = fields
  @form_method = form_method
  @rel = rel
  @enctype = enctype
  @action = action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/prismic/form.rb', line 4

def action
  @action
end

#enctypeObject

Returns the value of attribute enctype.



4
5
6
# File 'lib/prismic/form.rb', line 4

def enctype
  @enctype
end

#fieldsObject

Returns the value of attribute fields.



4
5
6
# File 'lib/prismic/form.rb', line 4

def fields
  @fields
end

#form_methodObject

Returns the value of attribute form_method.



4
5
6
# File 'lib/prismic/form.rb', line 4

def form_method
  @form_method
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/prismic/form.rb', line 4

def name
  @name
end

#relObject

Returns the value of attribute rel.



4
5
6
# File 'lib/prismic/form.rb', line 4

def rel
  @rel
end

Class Method Details

.from_json(api, json) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/prismic/form.rb', line 24

def self.from_json(api, json)
  Form.new(
      api,
      json['name'],
      Hash[json['fields'].map { |k2, field|
        [k2, Field.new(field['type'], field['default'], k2 == 'q')]
      }],
      json['method'],
      json['rel'],
      json['enctype'],
      json['action']
  )
end

Instance Method Details

#create_search_form(data = {}, ref = nil) ⇒ Object



20
21
22
# File 'lib/prismic/form.rb', line 20

def create_search_form(data={}, ref=nil)
  SearchForm.new(@api, self, data, ref)
end

#default_dataObject



16
17
18
# File 'lib/prismic/form.rb', line 16

def default_data
  Hash[fields.map{|key, field| [key, field.default] if field.default }.compact]
end