class Aspire::Object::Resource
Constants
- PAGE_RANGE
Attributes
@!attribute [rw] book_jacket_url
@return [String] the book jacket image URL
@!attribute [rw] date
@return [String] the date of publication
@!attribute [rw] doi
@return [String] the DOI for the resource
@!attribute [rw] edition
@return [String] the edition
@!attribute [rw] edition_data
@return [Boolean] true if edition data is available
@!attribute [rw] eissn
@return [String] the electronic ISSN for the resource
@!attribute [rw] has_part
@return [Array<Aspire::Object::Resource>] child resources
@!attribute [rw] is_part_of
@return [Array<Aspire::Object::Resource>] parent resources
@!attribute [rw] isbn10
@return [String] the 10-digit ISBN for the resource
@!attribute [rw] isbn13
@return [String] the 13-digit ISBN for the resource
@!attribute [rw] isbns
@return [Array<String>] the list of ISBNs for the resource
@!attribute [rw] issn
@return [Array<String>] the ISSN for the resource
@!attribute [rw] issue
@return [String] the issue
@!attribute [rw] issued
@return [String] the issue date
@!attribute [rw] latest_edition
@return [Boolean] true if this is the latest edition
@!attribute [rw] local_control_number
@return [String] the local control number in the library catalogue
@!attribute [rw] online_resource
@return [Boolean] true if this is an online resource
@!attribute [rw] page
@return [String] the page range
@!attribute [rw] page_end
@return [String] the end page
@!attribute [rw] page_start
@return [String] the start page
@!attribute [rw] place_of_publication
@return [String] the place of publication
@!attribute [rw] publisher
@return [String] the publisher
@!attribute [rw] title
@return [String] the title of the resource
@!attribute [rw] type
@return [String] the type of the resource
@!attribute [rw] url
@return [String] the URL of the resource
@!attribute [rw] volume
@return [String] the volume
Public Class Methods
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]
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
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
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
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
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
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
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
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
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
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