Class: STAC::ObjectResolver
- Inherits:
-
Object
- Object
- STAC::ObjectResolver
- Defined in:
- lib/stac/object_resolver.rb
Overview
Resolves a STAC object from a URL.
Class Attribute Summary collapse
-
.resolvables ⇒ Object
readonly
Resolvable classes.
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
Instance Method Summary collapse
-
#initialize(http_client:) ⇒ ObjectResolver
constructor
A new instance of ObjectResolver.
-
#resolve(url) ⇒ Object
Reads a JSON from the given URL and returns a STAC object resolved from it.
Constructor Details
#initialize(http_client:) ⇒ ObjectResolver
Returns a new instance of ObjectResolver.
21 22 23 |
# File 'lib/stac/object_resolver.rb', line 21 def initialize(http_client:) @http_client = http_client end |
Class Attribute Details
.resolvables ⇒ Object (readonly)
Resolvable classes. Default is Catalog, Collection and Item.
14 15 16 |
# File 'lib/stac/object_resolver.rb', line 14 def resolvables @resolvables end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
19 20 21 |
# File 'lib/stac/object_resolver.rb', line 19 def http_client @http_client end |
Instance Method Details
#resolve(url) ⇒ Object
Reads a JSON from the given URL and returns a STAC object resolved from it.
Supports the following URL scheme:
-
http
-
https
-
file
Raises:
-
STAC::NotSupportedURISchemeError when a URL with not supported scheme was given
-
STAC::TypeError when it could not resolve any STAC objects
35 36 37 38 39 40 41 42 43 |
# File 'lib/stac/object_resolver.rb', line 35 def resolve(url) hash = read(url) klass = self.class.resolvables.find { |c| c.type == hash['type'] } raise TypeError, "unknown STAC object type: #{hash['type']}" unless klass object = klass.from_hash(hash) object.http_client = http_client object end |