Class: Arx::Paper
- Inherits:
-
Object
- Object
- Arx::Paper
- Includes:
- Inspector, HappyMapper
- Defined in:
- lib/arx/entities/paper.rb
Overview
Entity/model representing an arXiv paper.
Constant Summary collapse
- ATTRIBUTES =
%i[ id url version revision? title summary authors primary_category categories published_at updated_at comment? comment journal? journal pdf? pdf_url doi? doi_url ]
Instance Method Summary collapse
-
#==(paper) ⇒ Boolean
Equality check against another paper.
-
#as_json ⇒ Hash
Serializes the Paper object into a valid JSON hash.
-
#authors ⇒ Array<Author>
The authors of the paper.
-
#categories ⇒ Array<Category>
The categories of the paper.
-
#comment ⇒ String
The comment of the paper.
-
#comment? ⇒ Boolean
Whether or not the paper has a comment.
-
#doi? ⇒ Boolean
Whether or not the paper has a DOI (Digital Object Identifier) link.
-
#doi_url ⇒ String
Link to the DOI (Digital Object Identifier) of the paper.
-
#id(version = false) ⇒ String
The identifier of the paper.
-
#journal ⇒ String
The journal reference of the paper.
-
#journal? ⇒ Boolean
Whether or not the paper has a journal reference.
-
#pdf? ⇒ Boolean
Whether or not the paper has a PDF link.
-
#pdf_url ⇒ String
Link to the PDF version of the paper.
-
#primary_category ⇒ Category
(also: #category)
The primary category of the paper.
-
#published_at ⇒ DateTime
The original publish/submission date of the paper.
-
#revision? ⇒ Boolean
Whether the paper is a revision or not.
-
#save(path) ⇒ Object
Downloads the paper and saves it in PDF format at the specified path.
-
#summary ⇒ String
(also: #abstract)
The summary (or abstract) of the paper.
-
#title ⇒ DateTime
The title of the paper.
-
#to_h(deep = false) ⇒ Hash
Serializes the Paper object into a
Hash
. -
#to_json ⇒ String
Serializes the Paper object into a valid JSON string.
-
#to_s ⇒ String
A string representation of the Paper object.
-
#updated_at ⇒ DateTime
The date that the paper was last updated.
-
#url(version = false) ⇒ String
The URL of the paper on the arXiv website.
-
#version ⇒ Integer
The version of the paper.
Methods included from Inspector
Instance Method Details
#==(paper) ⇒ Boolean
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.
Equality check against another paper.
230 231 232 233 234 235 236 |
# File 'lib/arx/entities/paper.rb', line 230 def ==(paper) if paper.is_a? Paper id == paper.id else false end end |
#as_json ⇒ Hash
Serializes the Arx::Paper object into a valid JSON hash.
212 213 214 |
# File 'lib/arx/entities/paper.rb', line 212 def as_json JSON.parse to_json end |
#authors ⇒ Array<Author>
The authors of the paper.
84 |
# File 'lib/arx/entities/paper.rb', line 84 has_many :authors, Author, tag: 'author' |
#categories ⇒ Array<Category>
The categories of the paper.
97 |
# File 'lib/arx/entities/paper.rb', line 97 has_many :categories, Category, tag: 'category' |
#comment ⇒ String
This is an optional metadata field on an arXiv paper. To check whether the paper has a comment, use #comment?
The comment of the paper.
117 |
# File 'lib/arx/entities/paper.rb', line 117 element :comment, Cleaner, parser: :clean, tag: 'comment' |
#comment? ⇒ Boolean
Whether or not the paper has a comment.
|
# File 'lib/arx/entities/paper.rb', line 106
|
#doi? ⇒ Boolean
Whether or not the paper has a DOI (Digital Object Identifier) link.
|
# File 'lib/arx/entities/paper.rb', line 162
|
#doi_url ⇒ String
This is an optional metadata field on an arXiv paper. To check whether the paper has a DOI link, use #doi?
Link to the DOI (Digital Object Identifier) of the paper.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/arx/entities/paper.rb', line 178 %i[pdf doi].each do |link_type| exists = "#{link_type}?".to_sym define_method exists do links.any? &exists end define_method "#{link_type}_url" do if self.send exists links.find(&exists).href else raise Error::MissingLink.new id, link_type.to_s.upcase end end end |
#id(version = false) ⇒ String
This is either in OLD_IDENTIFIER_FORMAT or NEW_IDENTIFIER_FORMAT.
The identifier of the paper.
32 33 34 |
# File 'lib/arx/entities/paper.rb', line 32 def id(version = false) Cleaner.extract_id @id, version: version end |
#journal ⇒ String
This is an optional metadata field on an arXiv paper. To check whether the paper has a journal reference, use #journal?
The journal reference of the paper.
130 |
# File 'lib/arx/entities/paper.rb', line 130 element :journal, Cleaner, parser: :clean, tag: 'journal_ref' |
#journal? ⇒ Boolean
Whether or not the paper has a journal reference.
|
# File 'lib/arx/entities/paper.rb', line 119
|
#pdf? ⇒ Boolean
Whether or not the paper has a PDF link.
|
# File 'lib/arx/entities/paper.rb', line 150
|
#pdf_url ⇒ String
This is an optional metadata field on an arXiv paper. To check whether the paper has a PDF link, use #pdf?
Link to the PDF version of the paper.
|
# File 'lib/arx/entities/paper.rb', line 155
|
#primary_category ⇒ Category Also known as: category
The primary category of the paper.
90 |
# File 'lib/arx/entities/paper.rb', line 90 element :primary_category, Category, tag: 'primary_category' |
#published_at ⇒ DateTime
The original publish/submission date of the paper.
72 |
# File 'lib/arx/entities/paper.rb', line 72 element :published_at, DateTime, tag: 'published' |
#revision? ⇒ Boolean
A paper is a revision if its #version is greater than 1.
Whether the paper is a revision or not.
58 59 60 |
# File 'lib/arx/entities/paper.rb', line 58 def revision? version > 1 end |
#save(path) ⇒ Object
Downloads the paper and saves it in PDF format at the specified path.
241 242 243 244 245 246 247 248 249 |
# 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 |
#summary ⇒ String Also known as: abstract
The summary (or abstract) of the paper.
103 |
# File 'lib/arx/entities/paper.rb', line 103 element :summary, Cleaner, parser: :clean, tag: 'summary' |
#title ⇒ DateTime
The title of the paper.
78 |
# File 'lib/arx/entities/paper.rb', line 78 element :title, Cleaner, parser: :clean, tag: 'title' |
#to_h(deep = false) ⇒ Hash
Serializes the Arx::Paper object into a Hash
.
198 199 200 201 202 203 204 205 206 |
# 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 |
#to_json ⇒ String
Serializes the Arx::Paper object into a valid JSON string.
220 221 222 |
# File 'lib/arx/entities/paper.rb', line 220 def to_json to_h(true).to_json end |
#to_s ⇒ String
A string representation of the Arx::Paper object.
254 255 256 257 258 259 260 |
# File 'lib/arx/entities/paper.rb', line 254 def to_s _id = id true _published_at = published_at.strftime("%Y-%m-%d") = .map(&:name) = [*.first(2), '...'] if .size > 2 "Arx::Paper(id: #{_id}, published_at: #{_published_at}, authors: [#{.join(', ')}], title: #{title})" end |
#updated_at ⇒ DateTime
The date that the paper was last updated.
66 |
# File 'lib/arx/entities/paper.rb', line 66 element :updated_at, DateTime, tag: 'updated' |
#url(version = false) ⇒ String
The URL of the paper on the arXiv website.
43 44 45 |
# File 'lib/arx/entities/paper.rb', line 43 def url(version = false) "http://arxiv.org/abs/#{id version}" end |
#version ⇒ Integer
The version of the paper.
50 51 52 |
# File 'lib/arx/entities/paper.rb', line 50 def version Cleaner.extract_version @id end |