Class: Aspire::Object::Factory

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/aspire/object/factory.rb

Overview

A factory returning reading list objects given the object’s URI

Constant Summary

Constants included from Util

Util::LD_API_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#child_url?, #duration, #id_from_uri, #item?, #linked_data, #linked_data_path, #list?, #list_url?, #module?, #parent_url?, #parse_url, #resource?, #section?, #url_for_comparison, #url_path, #user?

Constructor Details

#initialize(cache, users = nil) ⇒ void

Initialises a new Factory instance

Parameters:



26
27
28
29
# File 'lib/aspire/object/factory.rb', line 26

def initialize(cache, users = nil)
  self.cache = cache
  self.users = users || {}
end

Instance Attribute Details

#cacheAspire::Caching::Cache

Returns the cache for retrieving data.

Returns:



14
15
16
# File 'lib/aspire/object/factory.rb', line 14

def cache
  @cache
end

#usersHash<String, Aspire::Object::User>

Returns a hash of user profiles indexed by URI.

Returns:



19
20
21
# File 'lib/aspire/object/factory.rb', line 19

def users
  @users
end

Instance Method Details

#get(uri = nil, parent = nil, json: nil, ld: nil) ⇒ Aspire::Object::ListBase

Returns a new API list object (Aspire::Object::ListBase subclass) given its URI

Parameters:

  • uri (String) (defaults to: nil)

    the URI of the object

  • parent (Aspire::Object::ListBase) (defaults to: nil)

    this object’s parent object

  • json (Hash) (defaults to: nil)

    the parsed JSON API data for the object

  • ld (Hash) (defaults to: nil)

    the parsed linked data API data for the object

Returns:



38
39
40
41
42
# File 'lib/aspire/object/factory.rb', line 38

def get(uri = nil, parent = nil, json: nil, ld: nil)
  return nil if uri.nil? || uri.empty?
  get_exceptions(uri, parent, json: json, ld: ld) ||
    get_linked_data(uri, parent, json: json, ld: ld)
end