Class: Contentful::Field
- Inherits:
-
Object
- Object
- Contentful::Field
- Defined in:
- lib/contentful/field.rb
Overview
A ContentType's field schema See www.contentful.com/developers/documentation/content-management-api/#resources-content-types-fields
Constant Summary
- KNOWN_TYPES =
Coercions from Contentful Types to Ruby native types
{ 'String' => StringCoercion, 'Text' => TextCoercion, 'Symbol' => SymbolCoercion, 'Integer' => IntegerCoercion, 'Number' => FloatCoercion, 'Boolean' => BooleanCoercion, 'Date' => DateCoercion, 'Location' => LocationCoercion, 'Object' => ObjectCoercion, 'Array' => ArrayCoercion, 'Link' => LinkCoercion }
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#link_type ⇒ Object
readonly
Returns the value of attribute link_type.
-
#localized ⇒ Object
readonly
Returns the value of attribute localized.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#coerce(value) ⇒ Object
Coerces value to proper type.
-
#initialize(json) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(json) ⇒ Field
Returns a new instance of Field
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/contentful/field.rb', line 25 def initialize(json) @raw = json @id = json.fetch('id', nil) @name = json.fetch('name', nil) @type = json.fetch('type', nil) @link_type = json.fetch('linkType', nil) @items = json.key?('items') ? Field.new(json.fetch('items', {})) : nil @required = json.fetch('required', false) @localized = json.fetch('localized', false) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def id @id end |
#items ⇒ Object (readonly)
Returns the value of attribute items
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def items @items end |
#link_type ⇒ Object (readonly)
Returns the value of attribute link_type
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def link_type @link_type end |
#localized ⇒ Object (readonly)
Returns the value of attribute localized
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def localized @localized end |
#name ⇒ Object (readonly)
Returns the value of attribute name
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def name @name end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def raw @raw end |
#required ⇒ Object (readonly)
Returns the value of attribute required
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type
23 24 25 |
# File 'lib/contentful/field.rb', line 23 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
Coerces value to proper type
37 38 39 40 41 42 43 |
# File 'lib/contentful/field.rb', line 37 def coerce(value) return value if type.nil? = {} [:coercion_class] = KNOWN_TYPES[items.type] unless items.nil? KNOWN_TYPES[type].new(value, ).coerce end |