Class: Halva::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/halva/link.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href, relation, options = {}) ⇒ Link

Returns a new instance of Link.

Parameters:

  • href (String)
  • relation (Symbol)
  • options (Hash) (defaults to: {})

    (templated, type, deprecation, name, profile, title, hreflang)

Options Hash (options):

  • :templated (Boolean)

    true when the Link Object’s “href” property is a URI Template

  • :type (String)

    a hint to indicate the media type expected when dereferencing the target resource

  • :deprecation (String)

    indicate that the link is to be deprecated (i.e. removed) at a future date

  • :name (String)

    a secondary key for selecting Link Objects which share the same relation type

  • :profile (String)

    a URI that hints about the profile of the target resource

  • :title (String)

    label for the link with a human-readable identifier

  • :hreflang (String)

    indicate the language of the target resource



19
20
21
22
23
# File 'lib/halva/link.rb', line 19

def initialize(href, relation, options = {})
  @href = href
  @relation = relation.to_sym
  @options = options
end

Instance Attribute Details

#relationObject (readonly)

Returns the value of attribute relation.



7
8
9
# File 'lib/halva/link.rb', line 7

def relation
  @relation
end

Instance Method Details

#to_hObject



25
26
27
# File 'lib/halva/link.rb', line 25

def to_h
  { href: @href, **@options }
end