class STAC::Link
Represents STAC link object, which describes a relationship with another entity.
Attributes
href[W]
owner[RW]
Owner object of this link.
rel[RW]
title[RW]
type[RW]
Public Class Methods
from_hash(hash)
click to toggle source
Deserializes a Link
from a Hash.
# File lib/stac/link.rb, line 25 def from_hash(hash) new(**hash.transform_keys(&:to_sym)) end
new(target = nil, rel:, href:, type: nil, title: nil, **extra)
click to toggle source
# File lib/stac/link.rb, line 37 def initialize(target = nil, rel:, href:, type: nil, title: nil, **extra) @target = target @rel = rel @href = href @type = type @title = title @extra = extra.transform_keys(&:to_s) end
Public Instance Methods
absolute_href()
click to toggle source
Returns the absolute HREF for this link.
# File lib/stac/link.rb, line 66 def absolute_href if URI(href!).absolute? href! elsif (base_href = owner&.self_href) Pathname(base_href).dirname.join(href!).to_s end end
href()
click to toggle source
# File lib/stac/link.rb, line 61 def href @href || @target&.self_href end
relative_href()
click to toggle source
Returns the relative HREF for this link.
# File lib/stac/link.rb, line 75 def relative_href if URI(href!).relative? href! elsif (base_href = owner&.self_href) Pathname(href!).relative_path_from(Pathname(base_href).dirname).to_s end end
resolved?()
click to toggle source
Determines if the link’s target is a resolved STACObject
.
# File lib/stac/link.rb, line 57 def resolved? !@target.nil? end
target(http_client: owner&.http_client || STAC.default_http_client)
click to toggle source
Returns a STAC object resolved from HREF.
When it could not assemble the absolute HREF, it returns nil.
# File lib/stac/link.rb, line 86 def target(http_client: owner&.http_client || STAC.default_http_client) @target ||= if (url = absolute_href) object = ObjectResolver.new(http_client: http_client).resolve(url) object.self_href = url object end end
to_h()
click to toggle source
Serializes self to a Hash.
# File lib/stac/link.rb, line 47 def to_h { 'rel' => rel, 'href' => href, 'type' => type, 'title' => title, }.merge(extra).compact end