class Aspire::Object::Resource

Represents a resource in the Aspire API

Constants

PAGE_RANGE

Attributes

authors[RW]

@!attribute [rw] authors

@return [Array<String>] the list of authors of the resource
book_jacket_url[RW]

@!attribute [rw] book_jacket_url

@return [String] the book jacket image URL
date[RW]

@!attribute [rw] date

@return [String] the date of publication
doi[RW]

@!attribute [rw] doi

@return [String] the DOI for the resource
edition[RW]

@!attribute [rw] edition

@return [String] the edition
edition_data[RW]

@!attribute [rw] edition_data

@return [Boolean] true if edition data is available
eissn[RW]

@!attribute [rw] eissn

@return [String] the electronic ISSN for the resource
has_part[RW]

@!attribute [rw] has_part

@return [Array<Aspire::Object::Resource>] child resources
is_part_of[RW]

@!attribute [rw] is_part_of

@return [Array<Aspire::Object::Resource>] parent resources
isbn10[RW]

@!attribute [rw] isbn10

@return [String] the 10-digit ISBN for the resource
isbn13[RW]

@!attribute [rw] isbn13

@return [String] the 13-digit ISBN for the resource
isbns[RW]

@!attribute [rw] isbns

@return [Array<String>] the list of ISBNs for the resource
issn[RW]

@!attribute [rw] issn

@return [Array<String>] the ISSN for the resource
issue[RW]

@!attribute [rw] issue

@return [String] the issue
issued[RW]

@!attribute [rw] issued

@return [String] the issue date
latest_edition[RW]

@!attribute [rw] latest_edition

@return [Boolean] true if this is the latest edition
local_control_number[RW]

@!attribute [rw] local_control_number

@return [String] the local control number in the library catalogue
online_resource[RW]

@!attribute [rw] online_resource

@return [Boolean] true if this is an online resource
page[RW]

@!attribute [rw] page

@return [String] the page range
page_end[RW]

@!attribute [rw] page_end

@return [String] the end page
page_start[RW]

@!attribute [rw] page_start

@return [String] the start page
place_of_publication[RW]

@!attribute [rw] place_of_publication

@return [String] the place of publication
publisher[RW]

@!attribute [rw] publisher

@return [String] the publisher
title[RW]

@!attribute [rw] title

@return [String] the title of the resource
type[RW]

@!attribute [rw] type

@return [String] the type of the resource
url[RW]

@!attribute [rw] url

@return [String] the URL of the resource
volume[RW]

@!attribute [rw] volume

@return [String] the volume

Public Class Methods

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

Initialises a new Resource instance @param json [Hash] the resource data from the Aspire JSON API @param ld [Hash] the resource data from the Aspire linked data API @return [void]

Calls superclass method Aspire::Object::Base::new
# File lib/aspire/object/resource.rb, line 250
def initialize(uri = nil, factory = nil, json: nil, ld: nil)
  uri ||= json ? json['uri'] : nil
  super(uri, factory)
  return unless json
  init_general(json)
  init_components(json)
  init_edition(json)
  init_identifiers(json)
  init_part(json)
  init_publication(json)
end

Public Instance Methods

page=(value) click to toggle source

Sets the page range and updates the page_start and page_end properties @param value [String] the page range “start-end” @return [String] the page range “start-end”

# File lib/aspire/object/resource.rb, line 265
def page=(value)
  @page = value.to_s
  match = PAGE_RANGE.match(@page)
  if match.nil?
    # Value is not a range, treat as a single page
    @page_end = @page
    @page_start = @page
  else
    # Value is a range
    @page_end = match[:end]
    @page_start = match[:start]
  end
  @page
end
page_range() click to toggle source

Returns the page range spanned by the page_start and page_end properties @return [String] the page range “start-end” or page number

# File lib/aspire/object/resource.rb, line 282
def page_range
  return @page_start if @page_end.nil? || @page_start == @page_end
  return @page_end if @page_start.nil?
  "#{@page_start}-#{@page_end}"
end
to_s() click to toggle source

Returns a string representation of the resource (the title) @return [String] the string representation of the resource

# File lib/aspire/object/resource.rb, line 290
def to_s
  title
end

Protected Instance Methods

init_components(json) click to toggle source

Sets the component-related properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 299
def init_components(json)
  has_part = json['hasPart']
  is_part_of = json['isPartOf']
  self.has_part = has_part ? factory.get(uri, json: has_part) : nil
  self.is_part_of = is_part_of ? factory.get(uri, json: is_part_of) : nil
end
init_edition(json) click to toggle source

Sets the edition-related properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 309
def init_edition(json)
  self.edition = get_property('edition', json)
  self.edition_data = get_property('editionData', json)
  self.latest_edition = get_property('latestEdition', json)
end
init_general(json) click to toggle source

Sets general resource properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 318
def init_general(json)
  self.authors = get_property('authors', json, single: false)
  self.book_jacket_url = get_property('bookjacketURL', json)
  self.issued = json ? json['issued'] : nil # TODO
  self.online_resource = get_boolean('onlineResource', json)
  self.title = get_property('title', json)
  self.type = get_property('type', json)
  self.url = get_property('url', json, is_url: true)
end
init_identifiers(json) click to toggle source

Sets the identifier properties (DOI, ISBN/ISSN, local control number) @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 331
def init_identifiers(json)
  self.doi = get_property('doi', json)
  self.eissn = get_property('eissn', json)
  self.isbn10 = get_property('isbn10', json)
  self.isbn13 = get_property('isbn13', json)
  self.isbns = get_property('isbns', json, single: false)
  self.issn = get_property('issn', json)
  self.local_control_number = get_property('lcn', json)
end
init_pagination(json) click to toggle source

Sets the pagination-related properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 344
def init_pagination(json)
  self.page_end = get_property('pageEnd', json)
  self.page_start = get_property('pageStart', json)
  # Override page_end and page_start if the page range is specified
  range = get_property('page', json)
  self.page = range unless range.nil? || range.empty?
end
init_part(json) click to toggle source

Sets the part-related properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 355
def init_part(json)
  init_pagination(json)
  self.issue = get_property('issue', json)
  self.volume = get_property('volume', json)
end
init_publication(json) click to toggle source

Sets the publication-related properties @param json [Hash] the resource data from the Aspire JSON API @return [void]

# File lib/aspire/object/resource.rb, line 364
def init_publication(json)
  self.date = get_property('date', json)
  self.place_of_publication = get_property('placeOfPublication', json)
  self.publisher = get_property('publisher', json)
end