Class: WCC::Contentful::Link
- Inherits:
-
Object
- Object
- WCC::Contentful::Link
- Defined in:
- lib/wcc/contentful/link.rb
Constant Summary collapse
- LINK_TYPES =
{ Asset: 'Asset', Link: 'Entry' }.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#link_type ⇒ Object
readonly
Returns the value of attribute link_type.
-
#raw ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(model, link_type = nil) ⇒ Link
constructor
A new instance of Link.
Constructor Details
#initialize(model, link_type = nil) ⇒ Link
Returns a new instance of Link.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wcc/contentful/link.rb', line 11 def initialize(model, link_type = nil) @id = model.try(:id) || model @link_type = link_type @link_type ||= model.is_a?(WCC::Contentful::Model::Asset) ? :Asset : :Link @raw = { 'sys' => { 'type' => 'Link', 'linkType' => LINK_TYPES[@link_type] || link_type, 'id' => @id } } end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/wcc/contentful/link.rb', line 4 def id @id end |
#link_type ⇒ Object (readonly)
Returns the value of attribute link_type.
4 5 6 |
# File 'lib/wcc/contentful/link.rb', line 4 def link_type @link_type end |
#raw ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute raw.
4 5 6 |
# File 'lib/wcc/contentful/link.rb', line 4 def raw @raw end |