class Aspire::Object::List
Attributes
@!attribute [rw] created
@return [DateTime] the creation timestamp of the list
@!attribute [rw] creator
@return [Array<Aspire::Object::User>] the reading list creators
@!attribute [rw] description
@return [String] the description of the list
@!attribute [rw] items
@return [Hash<String, Aspire::Object::ListItem>] a hash of ListItems indexed by item URI
@!attribute [rw] last_published
@return [DateTime] the timestamp of the most recent list publication
@!attribute [rw] last_updated
@return [DateTime] the timestamp of the most recent list update
@!attribute [rw] modules
@return [Array<Aspire::Object::Module>] the modules referencing this list
@!attribute [rw] name
@return [String] the reading list name
@!attribute [rw] owner
@return [Aspire::Object::User] the list owner
@!attribute [rw] publisher
@return [Aspire::Object::User] the list publisher
@!attribute [rw] time_period
@return [Aspire::Object::TimePeriod] the period covered by the list
Public Class Methods
Initialises a new List
instance @param uri [String] the URI of the object @param factory [Aspire::Object::Factory] a factory returning ListBase
subclass instances
@param parent [Aspire::Object::ListBase] this object’s parent object @param json [Hash] the parsed JSON data from the Aspire
JSON API
@param ld [Hash] the parsed JSON data from the Aspire
linked data API
@return [void]
Aspire::Object::ListBase::new
# File lib/aspire/object/list.rb, line 266 def initialize(uri, factory, parent = nil, json: nil, ld: nil) # Set properties from the Reading Lists JSON API # - this must be called before the superclass constructor so that item # details are available init_json_data(uri, factory, json) # Initialise the superclass super(uri, factory, parent, json: json, ld: ld) # Set properties from the linked data API data init_linked_data(ld) end
Public Instance Methods
Returns the number of items in the list @see (Aspire::Object::ListBase#length
)
Aspire::Object::ListBase#length
# File lib/aspire/object/list.rb, line 279 def length(item_type = nil) item_type ||= :item # The item length of a list is the length of the items property, # avoiding the need to sum list entry lengths item_type == :item ? items.length : super(item_type) end
Returns a string representation of the List
instance (the name) @return [String] the string representation of the List
instance
Aspire::Object::Base#to_s
# File lib/aspire/object/list.rb, line 288 def to_s name || super end
Private Instance Methods
Retrieves the list details and history from the Aspire
JSON API
@param uri [String] the URI of the object @param factory [Aspire::Object::Factory] a factory returning ListBase
subclass instances
@param json [Hash] the parsed JSON data from the Aspire
JSON API
@return [void]
# File lib/aspire/object/list.rb, line 300 def init_json_data(uri, factory, json = nil) init_json_defaults # Get the list details json ||= factory.cache.read(uri, json: true) if json self.name = json['name'] init_json_items(json['items']) init_json_modules(json['modules'], factory) init_json_time_period(json['timePeriod'], factory) end # Return the parsed JSON data from the Aspire list details JSON API json end
Sets the property defaults for JSON API
fields @return [void]
# File lib/aspire/object/list.rb, line 316 def init_json_defaults # Default values self.modules = nil self.name = nil self.time_period = nil end
Builds a mapping from item URI to JSON data for items from the JSON API
@param items [Array<Hash>] the parsed JSON data for the items array @return [void]
# File lib/aspire/object/list.rb, line 326 def init_json_items(items) # A hash mapping item URI to item self.items = {} return unless items items.each { |item| self.items[item['uri']] = item } end
Builds a list of Module
instances for modules from the JSON API
@param mods [Array<Hash>] the parsed JSON data for the modules array @param factory [Aspire::Object::Factory] a factory returning ListBase
subclass instances
@return [void]
# File lib/aspire/object/list.rb, line 338 def init_json_modules(mods, factory) return unless mods self.modules = mods.map { |m| Module.new(m['uri'], factory, json: m) } end
Sets the time period for the list from the JSON API
@param period [Array<Hash>] the parsed JSON data for the time period @param factory [Aspire::Object::Factory] a factory returning ListBase
subclass instances
@return [void]
# File lib/aspire/object/list.rb, line 348 def init_json_time_period(period, factory) self.time_period = if period TimePeriod.new(period['uri'], factory, json: period) end end
Sets reading list properties from the Aspire
linked data API
@return [void]
# File lib/aspire/object/list.rb, line 357 def init_linked_data(ld = nil) list_data = linked_data(uri, ld) init_linked_data_creator(list_data, ld) init_linked_data_modules(list_data, ld) init_linked_data_owner(list_data, ld) init_linked_data_publisher(list_data, ld) self.created = get_date(CREATED, list_data) self.description = get_property(DESCRIPTION, list_data) self.last_published = get_date(LAST_PUBLISHED, list_data) self.last_updated = get_date(LAST_UPDATED, list_data) self.name = get_property(NAME, list_data) unless name end
Sets the reading list creator @param list_data [Hash] the parsed JSON data for the list from the
Aspire linked data API
@param ld [Hash] the parsed JSON data from the Aspire
linked data API
@return [void]
# File lib/aspire/object/list.rb, line 375 def init_linked_data_creator(list_data, ld) has_creator = get_property(HAS_CREATOR, list_data, single: false) || [] self.creator = has_creator.map { |u| factory.get(u, ld: ld) } end
Sets the list modules @param list_data [Hash] the parsed JSON data for the list from the
Aspire linked data API
@param ld [Hash] the parsed JSON data from the Aspire
linked data API
@return [void]
# File lib/aspire/object/list.rb, line 385 def init_linked_data_modules(list_data, ld) return unless modules.nil? mods = get_property(USED_BY, list_data, single: false) || [] self.modules = mods.map { |u| factory.get(u, ld: ld) } if mods end
Sets the list owner @param list_data [Hash] the parsed JSON data for the list from the
Aspire linked data API
@param ld [Hash] the parsed JSON data from the Aspire
linked data API
@return [void]
# File lib/aspire/object/list.rb, line 396 def init_linked_data_owner(list_data, ld) has_owner = get_property(HAS_OWNER, list_data, single: false) || [] self.owner = has_owner.map { |u| factory.get(u, ld: ld) } end
Sets the list publisher @param list_data [Hash] the parsed JSON data for the list from the
Aspire linked data API
@param ld [Hash] the parsed JSON data from the Aspire
linked data API
@return [void]
# File lib/aspire/object/list.rb, line 406 def init_linked_data_publisher(list_data, ld) published_by = get_property(PUBLISHED_BY, list_data) self.publisher = factory.get(published_by, ld: ld) end