class ContentfulLite::Link

A link to any type of contentful entity

Attributes

id[R]

The unique id of the linked entity

type[R]

The type of the linked entity

Public Class Methods

new(input) click to toggle source

@param input [ContentfulLite::CommonData, Hash] data to build the instance @api private

# 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

Public Instance Methods

==(other) click to toggle source

Equality comparison @param other [Object] the object to compare @return [Boolean] true if other is ContentfulLite::Link with same id and type

# File lib/contentful_lite/link.rb, line 24
def ==(other)
  self.class == other.class && type == other.type && id == other.id
end
as_json(**) click to toggle source

Provided for compatibility with Rails JSON serializer @return [Hash] a Hash representation of the link, to be formated as JSON

# File lib/contentful_lite/link.rb, line 30
def as_json(**)
  {
    'sys' => {
      'type' => "Link",
      'linkType' => type.to_s.capitalize,
      'id' => id
    }
  }
end