Class: ShafClient::Link

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

Direct Known Subclasses

Curie

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href:, templated: false) ⇒ Link

Returns a new instance of Link.



13
14
15
16
# File 'lib/shaf_client/link.rb', line 13

def initialize(href:, templated: false)
  @href = href
  @templated = !!templated
end

Class Method Details

.from(data) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/shaf_client/link.rb', line 5

def self.from(data)
  if data.is_a? Array
    data.map { |d| new(href: d['href'], templated: d['templated']) }
  else
    new(href: data['href'], templated: data['templated'])
  end
end

Instance Method Details

#hrefObject



22
23
24
# File 'lib/shaf_client/link.rb', line 22

def href
  @href.dup
end

#resolve_templated(**args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/shaf_client/link.rb', line 26

def resolve_templated(**args)
  return href unless templated?

  href
    .then { |href| resolve_required(href, **args) }
    .then { |href| resolve_optional(href, **args) }
end

#templated?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/shaf_client/link.rb', line 18

def templated?
  @templated
end

#to_hObject



34
35
36
37
38
39
# File 'lib/shaf_client/link.rb', line 34

def to_h
  {
    href: href,
    templated: templated?
  }
end