Class: Aspire::Object::List

Inherits:
ListBase show all
Includes:
Properties
Defined in:
lib/aspire/object/list.rb

Overview

Represents a reading list in the Aspire API

Constant Summary

Constants included from Properties

Properties::AIISO_CODE, Properties::AIISO_NAME, Properties::CREATED, Properties::DESCRIPTION, Properties::HAS_CREATOR, Properties::HAS_OWNER, Properties::LAST_PUBLISHED, Properties::LAST_UPDATED, Properties::NAME, Properties::PUBLISHED_BY, Properties::USED_BY

Constants inherited from ListBase

Aspire::Object::ListBase::KEY_PREFIX

Constants inherited from Base

Base::STRIP_HTML

Constants included from Util

Util::LD_API_URI

Instance Attribute Summary collapse

Attributes inherited from ListBase

#entries, #parent

Attributes inherited from Base

#factory, #uri

Instance Method Summary collapse

Methods inherited from ListBase

#each, #each_item, #each_section, #get_entries, #parent_list, #parent_lists, #parent_section, #parent_sections, #parents, #parents_include?, #sections

Methods inherited from Base

#get_boolean, #get_date, #get_property

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(uri, factory, parent = nil, json: nil, ld: nil) ⇒ void

Initialises a new List instance

Parameters:

  • uri (String)

    the URI of the object

  • factory (Aspire::Object::Factory)

    a factory returning ListBase subclass instances

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

    this object’s parent object

  • json (Hash) (defaults to: nil)

    the parsed JSON data from the Aspire JSON API

  • ld (Hash) (defaults to: nil)

    the parsed JSON data from the Aspire linked data API



266
267
268
269
270
271
272
273
274
275
# 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

Instance Attribute Details

#createdDateTime

Returns the creation timestamp of the list.

Returns:

  • (DateTime)

    the creation timestamp of the list



214
215
216
# File 'lib/aspire/object/list.rb', line 214

def created
  @created
end

#creatorArray<Aspire::Object::User>

Returns the reading list creators.

Returns:



218
219
220
# File 'lib/aspire/object/list.rb', line 218

def creator
  @creator
end

#descriptionString

Returns the description of the list.

Returns:

  • (String)

    the description of the list



222
223
224
# File 'lib/aspire/object/list.rb', line 222

def description
  @description
end

#itemsHash<String, Aspire::Object::ListItem>

Returns a hash of ListItems indexed by item URI.

Returns:



227
228
229
# File 'lib/aspire/object/list.rb', line 227

def items
  @items
end

#last_publishedDateTime

Returns the timestamp of the most recent list publication.

Returns:

  • (DateTime)

    the timestamp of the most recent list publication



231
232
233
# File 'lib/aspire/object/list.rb', line 231

def last_published
  @last_published
end

#last_updatedDateTime

Returns the timestamp of the most recent list update.

Returns:

  • (DateTime)

    the timestamp of the most recent list update



235
236
237
# File 'lib/aspire/object/list.rb', line 235

def last_updated
  @last_updated
end

#modulesArray<Aspire::Object::Module>

Returns the modules referencing this list.

Returns:



240
241
242
# File 'lib/aspire/object/list.rb', line 240

def modules
  @modules
end

#nameString

Returns the reading list name.

Returns:

  • (String)

    the reading list name



244
245
246
# File 'lib/aspire/object/list.rb', line 244

def name
  @name
end

#ownerAspire::Object::User

Returns the list owner.

Returns:



248
249
250
# File 'lib/aspire/object/list.rb', line 248

def owner
  @owner
end

#publisherAspire::Object::User

Returns the list publisher.

Returns:



252
253
254
# File 'lib/aspire/object/list.rb', line 252

def publisher
  @publisher
end

#time_periodAspire::Object::TimePeriod

Returns the period covered by the list.

Returns:



256
257
258
# File 'lib/aspire/object/list.rb', line 256

def time_period
  @time_period
end

Instance Method Details

#length(item_type = nil) ⇒ Object

Returns the number of items in the list

See Also:

  • Aspire::Object::List.(Aspire(Aspire::Object(Aspire::Object::ListBase(Aspire::Object::ListBase#length)


279
280
281
282
283
284
# 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

#to_sString

Returns a string representation of the List instance (the name)

Returns:

  • (String)

    the string representation of the List instance



288
289
290
# File 'lib/aspire/object/list.rb', line 288

def to_s
  name || super
end