Class: ContentfulLite::Link
- Inherits:
-
Object
- Object
- ContentfulLite::Link
- Defined in:
- lib/contentful_lite/link.rb
Overview
A link to any type of contentful entity
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The unique id of the linked entity.
-
#type ⇒ Object
readonly
The type of the linked entity.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality comparison.
-
#as_json ⇒ Hash
Provided for compatibility with Rails JSON serializer.
-
#initialize(input) ⇒ Link
constructor
private
A new instance of Link.
Constructor Details
#initialize(input) ⇒ Link
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Link.
11 12 13 14 15 16 17 18 19 |
# File 'lib/contentful_lite/link.rb', line 11 def initialize(input) if input.is_a?(ContentfulLite::CommonData) @id = input.id @type = input.sys['type'].downcase.to_sym else @type = input['sys']['linkType'].downcase.to_sym @id = input['sys']['id'] end end |
Instance Attribute Details
#id ⇒ Object (readonly)
The unique id of the linked entity
5 6 7 |
# File 'lib/contentful_lite/link.rb', line 5 def id @id end |
#type ⇒ Object (readonly)
The type of the linked entity
7 8 9 |
# File 'lib/contentful_lite/link.rb', line 7 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Equality comparison
24 25 26 |
# File 'lib/contentful_lite/link.rb', line 24 def ==(other) self.class == other.class && type == other.type && id == other.id end |
#as_json ⇒ Hash
Provided for compatibility with Rails JSON serializer
30 31 32 33 34 35 36 37 38 |
# File 'lib/contentful_lite/link.rb', line 30 def as_json(*) { 'sys' => { 'type' => "Link", 'linkType' => type.to_s.capitalize, 'id' => id } } end |