Class: Contentful::ContentType

Inherits:
BaseResource show all
Defined in:
lib/contentful/content_type.rb

Overview

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#_metadata, #default_locale, #raw, #sys

Instance Method Summary collapse

Methods inherited from BaseResource

#==, #inspect, #marshal_dump, #marshal_load, #reload

Constructor Details

#initialize(item) ⇒ ContentType

Returns a new instance of ContentType.



11
12
13
14
15
16
17
18
# File 'lib/contentful/content_type.rb', line 11

def initialize(item, *)
  super

  @name = item.fetch('name', nil)
  @description = item.fetch('description', nil)
  @fields = item.fetch('fields', []).map { |field| Field.new(field) }
  @display_field = item.fetch('displayField', nil)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/contentful/content_type.rb', line 9

def description
  @description
end

#display_fieldObject (readonly) Also known as: displayField

Returns the value of attribute display_field.



9
10
11
# File 'lib/contentful/content_type.rb', line 9

def display_field
  @display_field
end

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/contentful/content_type.rb', line 9

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/contentful/content_type.rb', line 9

def name
  @name
end

Instance Method Details

#field_for(field_id) ⇒ Object

Field definition for field



21
22
23
# File 'lib/contentful/content_type.rb', line 21

def field_for(field_id)
  fields.detect { |f| Support.snakify(f.id) == Support.snakify(field_id) }
end