Class: ShafClient::Link
- Inherits:
-
Object
- Object
- ShafClient::Link
- Defined in:
- lib/shaf_client/link.rb
Direct Known Subclasses
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
- #templated? ⇒ Boolean
- #to_h ⇒ Object
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
#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 |
# 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
18 19 20 |
# File 'lib/shaf_client/link.rb', line 18 def templated? @templated end |
#to_h ⇒ Object
34 35 36 37 38 39 |
# File 'lib/shaf_client/link.rb', line 34 def to_h { href: href, templated: templated? } end |