Class: ShafClient::Curie

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Link

#href, #templated?

Constructor Details

#initialize(name:, href:, templated: nil) ⇒ Curie

Returns a new instance of Curie.



19
20
21
22
23
# File 'lib/shaf_client/curie.rb', line 19

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/shaf_client/curie.rb', line 7

def name
  @name
end

Class Method Details

.from(data) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/shaf_client/curie.rb', line 9

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

Instance Method Details

#resolve_templated(**args) ⇒ Object



25
26
27
28
# File 'lib/shaf_client/curie.rb', line 25

def resolve_templated(**args)
  args[:rel] &&= args[:rel].to_s.sub(/#{name}:/, '')
  super(**args)
end

#to_hObject



30
31
32
# File 'lib/shaf_client/curie.rb', line 30

def to_h
  {name: name}.merge(super)
end