class Arx::Paper
Entity/model representing an arXiv paper.
Constants
- ATTRIBUTES
The attributes of an arXiv paper. @note {comment}, {journal}, {pdf_url} and {doi_url} may raise errors when called.
Public Instance Methods
Equality check against another paper.
@note This only performs a basic equality check between the papers' identifiers (disregarding version).
This means that a different version of the same paper will be viewed as equal.
@param paper [Paper] The paper to compare against. @return [Boolean]
# File lib/arx/entities/paper.rb, line 230 def ==(paper) if paper.is_a? Paper id == paper.id else false end end
The identifier of the paper.
@note This is either in {OLD_IDENTIFIER_FORMAT} or {NEW_IDENTIFIER_FORMAT}. @example
1705.01662v1 cond-mat/0211034
@param version [Boolean] Whether or not to include the paper's version. @return [String] The paper's identifier.
# File lib/arx/entities/paper.rb, line 32 def id(version = false) Cleaner.extract_id @id, version: version end
Whether the paper is a revision or not.
@note A paper is a revision if its {version} is greater than 1. @return [Boolean]
# File lib/arx/entities/paper.rb, line 58 def revision? version > 1 end
Downloads the paper and saves it in PDF format at the specified path.
@param path [String] The file path to store the PDF at.
# File lib/arx/entities/paper.rb, line 241 def save(path) begin pdf_content = URI.open(pdf_url).read File.open(path, 'wb') {|f| f.write pdf_content} rescue File.delete(path) if File.file? path raise end end
Serializes the {Paper} object into a Hash
.
@param deep [Boolean] Whether to deep-serialize {Author} and {Category} objects. @return [Hash]
# File lib/arx/entities/paper.rb, line 198 def to_h(deep = false) Hash[*ATTRIBUTES.map {|_| [_, send(_)] rescue nil}.compact.flatten(1)].tap do |hash| if deep hash[:authors].map! &:to_h hash[:categories].map! &:to_h hash[:primary_category] = hash[:primary_category].to_h end end end
A string representation of the {Paper} object.
@return [String]
# File lib/arx/entities/paper.rb, line 254 def to_s _id = id true _published_at = published_at.strftime("%Y-%m-%d") _authors = authors.map(&:name) _authors = [*_authors.first(2), '...'] if _authors.size > 2 "Arx::Paper(id: #{_id}, published_at: #{_published_at}, authors: [#{_authors.join(', ')}], title: #{title})" end
The URL of the paper on the arXiv website.
@example
http://arxiv.org/abs/1705.01662v1 http://arxiv.org/abs/cond-mat/0211034
@param version [Boolean] Whether or not to include the paper's version. @return [String] The paper's arXiv URL.
# File lib/arx/entities/paper.rb, line 43 def url(version = false) "http://arxiv.org/abs/#{id version}" end
The version of the paper.
@return [Integer] The paper's version.
# File lib/arx/entities/paper.rb, line 50 def version Cleaner.extract_version @id end