class Aspire::Object::ListItem
Attributes
@!attribute [rw] digitisation
@return [Aspire::Object::Digitisation] the digitisation details for the item
@!attribute [rw] importance
@return [String] the importance of the item
@!attribute [rw] library_note
@return [String] the internal library note for the item
@!attribute [rw] local_control_number
@return [String] the identifier of the resource in the local library management system
@!attribute [rw] note
@return [String] the public note for the item
@!attribute [rw] resource
@return [Aspire::Object::Resource] the resource for the item
@!attribute [rw] student_note
@return [String] the public note for the item
@!attribute [rw] title
@return [String] the title of the item
Public Class Methods
Initialises a new ListItem
instance @param uri [String] the reading list object URI (item/list/section) @param factory [Aspire::Object::Factory]
a factory returning ReadingListBase subclass instances
@param parent [Aspire::Object::ListBase]
the parent reading list object of this 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 458 def initialize(uri, factory, parent = nil, json: nil, ld: nil) super(uri, factory, parent, json: json, ld: ld) json ||= init_list_items init_digitisation(json) init_resource(json) self.importance = get_property('importance', json) self.library_note = get_property('libraryNote', json) self.local_control_number = get_property('lcn', json) self.note = get_property('note', json) self.student_note = get_property('studentNote', json) self.title = get_property('title', json) end
Public Instance Methods
Returns the length of the list item @see (Aspire::Object::ListBase#length
)
Aspire::Object::ListBase#length
# File lib/aspire/object/list.rb, line 473 def length(item_type = nil) item_type ||= :item # List items return an item length of 1 to enable summation of # list/section lengths item_type == :item ? 1 : super(item_type) end
Returns the public (student or general) note @return [String] the student note or general note
# File lib/aspire/object/list.rb, line 482 def public_note student_note || note end
Private Instance Methods
Returns the digitisation request JSON data if available, nil if not @param json [Hash] the JSON API
data @return [void]
# File lib/aspire/object/list.rb, line 513 def init_digitisation(json) dig_json = json ? json['digitisation'] : nil dig_ld = nil self.digitisation = if dig_json || dig_ld Digitisation.new(json: dig_json, ld: dig_ld) end end
Returns the list of JSON API
list items from the parent list @return [Array<Hash>] the list items, or nil if none are available
# File lib/aspire/object/list.rb, line 523 def init_list_items owner = parent_list owner && owner.items ? owner.items[uri] : nil end
Sets the resource @param json [Hash] the parsed JSON resource data @return nil
# File lib/aspire/object/list.rb, line 531 def init_resource(json) res_json = json ? json['resource'] : nil if res_json.is_a?(Array) res_json = res_json.empty? ? nil : res_json[0] puts("WARNING: used first resource of #{res_json}") if res_json end self.resource = factory.get(res_json['uri'], json: res_json) if res_json # resource_json = json ? json['resource'] : nil # resource_uri = get_property('http://purl.org/vocab/resourcelist/schema#resource', item_ld) # resource = resource_json # || resource_uri ? factory.get(resource_uri, json: resource_json, ld: ld) : nil end
Returns the alternative resource title @param (see title
) @return [String] the alternative to the resource title
# File lib/aspire/object/list.rb, line 546 def title_alt(alt) return library_note if %w[library_note private_note].include?(alt) return public_note || library_note if alt == :note return public_note if %w[public_note student_note].include?(alt) return uri if alt == :uri nil end