Class: ShafClient::Link
- Inherits:
-
Object
- Object
- ShafClient::Link
- Defined in:
- lib/shaf_client/link.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#templated ⇒ Object
(also: #templated?)
readonly
Returns the value of attribute templated.
Class Method Summary collapse
Instance Method Summary collapse
- #href ⇒ Object
-
#initialize(href:, templated: false) ⇒ Link
constructor
A new instance of Link.
- #resolve_templated(**args) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(href:, templated: false) ⇒ Link
Returns a new instance of Link.
15 16 17 18 |
# File 'lib/shaf_client/link.rb', line 15 def initialize(href:, templated: false) @href = href @templated = !!templated end |
Instance Attribute Details
#templated ⇒ Object (readonly) Also known as: templated?
Returns the value of attribute templated.
5 6 7 |
# File 'lib/shaf_client/link.rb', line 5 def templated @templated end |
Class Method Details
.from(data) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/shaf_client/link.rb', line 7 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
#href ⇒ Object
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 33 |
# File 'lib/shaf_client/link.rb', line 26 def resolve_templated(**args) return href unless templated? args.inject(href) do |uri, (key, value)| value = value.to_s.sub(/.+:/, '') uri.sub(/{#{key}}/, value) end end |
#to_h ⇒ Object
35 36 37 38 39 40 |
# File 'lib/shaf_client/link.rb', line 35 def to_h { href: href, templated: templated? } end |