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 collapse
- 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, 'RichText' => RichTextCoercion }
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, configuration) ⇒ 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.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/contentful/field.rb', line 26 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.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def id @id end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def items @items end |
#link_type ⇒ Object (readonly)
Returns the value of attribute link_type.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def link_type @link_type end |
#localized ⇒ Object (readonly)
Returns the value of attribute localized.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def localized @localized end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def name @name end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def raw @raw end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/contentful/field.rb', line 24 def type @type end |
Instance Method Details
#coerce(value, configuration) ⇒ Object
Coerces value to proper type
38 39 40 41 42 43 44 45 |
# File 'lib/contentful/field.rb', line 38 def coerce(value, configuration) return value if type.nil? return value if value.nil? = {} [:coercion_class] = KNOWN_TYPES[items.type] unless items.nil? KNOWN_TYPES[type].new(value, ).coerce(configuration) end |