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', Tag: 'Tag' }.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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wcc/contentful/link.rb', line 12 def initialize(model, link_type = nil) if model.is_a?(Hash) raise ArgumentError, 'Not a Link' unless model.dig('sys', 'type') == 'Link' @raw = model @id = model.dig('sys', 'id') @link_type = model.dig('sys', 'linkType') else @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 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 |