class Aspire::Object::ListItem

Represents a reading list item (citation) in the Aspire API

Attributes

digitisation[RW]

@!attribute [rw] digitisation

@return [Aspire::Object::Digitisation]
  the digitisation details for the item
importance[RW]

@!attribute [rw] importance

@return [String] the importance of the item
library_note[RW]

@!attribute [rw] library_note

@return [String] the internal library note for the item
local_control_number[RW]

@!attribute [rw] local_control_number

@return [String] the identifier of the resource in the local library
  management system
note[RW]

@!attribute [rw] note

@return [String] the public note for the item
resource[RW]

@!attribute [rw] resource

@return [Aspire::Object::Resource] the resource for
  the item
student_note[RW]

@!attribute [rw] student_note

@return [String] the public note for the item
title[RW]

@!attribute [rw] title

@return [String] the title of the item

Public Class Methods

new(uri, factory, parent = nil, json: nil, ld: nil) click to toggle source

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]

Calls superclass method 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

length(item_type = nil) click to toggle source

Returns the length of the list item @see (Aspire::Object::ListBase#length)

Calls superclass method 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
public_note() click to toggle source

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
to_s() click to toggle source

Returns a string representation of the ListItem instance (the citation

title or note)

@return [String] the string representation of the ListItem instance

# File lib/aspire/object/list.rb, line 504
def to_s
  title(:public_note).to_s
end

Private Instance Methods

init_digitisation(json) click to toggle source

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
init_list_items() click to toggle source

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
init_resource(json) click to toggle source

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
title_alt(alt) click to toggle source

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