Class: Prismic::Form
- Inherits:
-
Object
- Object
- Prismic::Form
- Defined in:
- lib/prismic/form.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#enctype ⇒ Object
Returns the value of attribute enctype.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#form_method ⇒ Object
Returns the value of attribute form_method.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rel ⇒ Object
Returns the value of attribute rel.
Class Method Summary collapse
Instance Method Summary collapse
- #create_search_form(data = {}, ref = nil) ⇒ Object
- #default_data ⇒ Object
-
#initialize(api, name, fields, form_method, rel, enctype, action) ⇒ Form
constructor
A new instance of Form.
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
#action ⇒ Object
Returns the value of attribute action
4 5 6 |
# File 'lib/prismic/form.rb', line 4 def action @action end |
#enctype ⇒ Object
Returns the value of attribute enctype
4 5 6 |
# File 'lib/prismic/form.rb', line 4 def enctype @enctype end |
#fields ⇒ Object
Returns the value of attribute fields
4 5 6 |
# File 'lib/prismic/form.rb', line 4 def fields @fields end |
#form_method ⇒ Object
Returns the value of attribute form_method
4 5 6 |
# File 'lib/prismic/form.rb', line 4 def form_method @form_method end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/prismic/form.rb', line 4 def name @name end |
#rel ⇒ Object
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_data ⇒ Object
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 |