arx 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +2 -2
- data/lib/arx.rb +28 -2
- data/lib/arx/cleaner.rb +1 -0
- data/lib/arx/entities/author.rb +3 -3
- data/lib/arx/entities/category.rb +3 -3
- data/lib/arx/entities/link.rb +1 -2
- data/lib/arx/entities/paper.rb +18 -14
- data/lib/arx/error.rb +27 -0
- data/lib/arx/inspector.rb +42 -0
- data/lib/arx/query/query.rb +0 -3
- data/lib/arx/query/validate.rb +1 -23
- data/lib/arx/version.rb +1 -1
- metadata +3 -2
- data/lib/arx/exceptions.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 292c64f4c39d1d5a1d20ea803f98bd2f02f9830af51babcb1d8a2048ca06b403
|
4
|
+
data.tar.gz: 75ad806933191bcbb3d84c6aad20bcc73f18c559c0c122ca57d49e23f3f7757a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b77f4ada7df3953695822feef7ca7e1f0feeb3d2a5375e3a37b9ae3a6db2d5c03db7979f19a19b6483e74226ca91113324052778a86a12b3f426e5689098b6a
|
7
|
+
data.tar.gz: 419f468c377406c8459528c8755330986b8c3c0545788a9efb99f0f1ee9902a9fc618f4dc760b7b083c9988180f8877cf7cc03ed1e0be8d725552105d7e72044
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# 0.3.1
|
2
|
+
|
3
|
+
#### Major changes
|
4
|
+
|
5
|
+
- Add `.yardopts` for document generation configuration. ([#26](https://github.com/eonu/arx/pull/26))
|
6
|
+
- Namespace errors in `Arx::Error` module and remove `Error` prefix from error classes. ([#26](https://github.com/eonu/arx/pull/26))
|
7
|
+
- Move identifier format regular expression constant definitions from `Arx::Validate` to top-level namespace `Arx`. ([#26](https://github.com/eonu/arx/pull/26))
|
8
|
+
|
9
|
+
#### Minor changes
|
10
|
+
|
11
|
+
- Rename `lib/arx/exceptions.rb` to `lib/arx/errors.rb`. ([#26](https://github.com/eonu/arx/pull/26))
|
12
|
+
- Make `Arx::Cleaner`, `Arx::Validate`, `Arx::Inspector`, `Arx::Link` private (hidden from `yard` documentation). ([#26](https://github.com/eonu/arx/pull/26))
|
13
|
+
|
1
14
|
# 0.3.0
|
2
15
|
|
3
16
|
#### Major changes
|
data/README.md
CHANGED
@@ -287,13 +287,13 @@ paper.revision?
|
|
287
287
|
paper.comment?
|
288
288
|
#=> false
|
289
289
|
paper.comment
|
290
|
-
#=> Arx::
|
290
|
+
#=> Arx::Error::MissingField (This arXiv paper is missing the `comment` field)
|
291
291
|
|
292
292
|
# Paper's journal reference
|
293
293
|
paper.journal?
|
294
294
|
#=> false
|
295
295
|
paper.journal
|
296
|
-
#=> Arx::
|
296
|
+
#=> Arx::Error::MissingField (This arXiv paper is missing the `journal` field)
|
297
297
|
|
298
298
|
# Paper's PDF URL
|
299
299
|
paper.pdf?
|
data/lib/arx.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'cgi'
|
3
4
|
require 'nokogiri'
|
4
5
|
require 'open-uri'
|
6
|
+
require 'happymapper'
|
5
7
|
require 'arx/version'
|
8
|
+
require 'arx/cleaner'
|
9
|
+
require 'arx/inspector'
|
6
10
|
require 'arx/categories'
|
7
|
-
require 'arx/
|
11
|
+
require 'arx/error'
|
8
12
|
require 'arx/query/validate'
|
13
|
+
require 'arx/query/query'
|
9
14
|
require 'arx/entities/author'
|
10
15
|
require 'arx/entities/category'
|
16
|
+
require 'arx/entities/link'
|
11
17
|
require 'arx/entities/paper'
|
12
18
|
|
13
19
|
# A Ruby interface for querying academic papers on the arXiv search API.
|
@@ -16,6 +22,26 @@ module Arx
|
|
16
22
|
# The arXiv search API endpoint.
|
17
23
|
ENDPOINT = 'http://export.arxiv.org/api/query?'
|
18
24
|
|
25
|
+
# The current arxiv paper identifier scheme (1 April 2007 and onwards).
|
26
|
+
# The last block of digits can either be five digits (if the paper was published after 1501 - January 2015),
|
27
|
+
# or four digits (if the paper was published before 1501).
|
28
|
+
#
|
29
|
+
# @see https://arxiv.org/help/arxiv_identifier#new arXiv identifier (new)
|
30
|
+
# @example
|
31
|
+
# 1501.00001
|
32
|
+
# 1705.01662v1
|
33
|
+
# 1412.0135
|
34
|
+
# 0706.0001v2
|
35
|
+
NEW_IDENTIFIER_FORMAT = %r"^\d{4}\.\d{4,5}(v\d+)?$"
|
36
|
+
|
37
|
+
# The legacy arXiv paper identifier scheme (before 1 April 2007).
|
38
|
+
#
|
39
|
+
# @see https://arxiv.org/help/arxiv_identifier#old arXiv identifier (old)
|
40
|
+
# @example
|
41
|
+
# math/0309136v1
|
42
|
+
# cond-mat/0211034
|
43
|
+
OLD_IDENTIFIER_FORMAT = %r"^[a-z]+(\-[a-z]+)?\/\d{7}(v\d+)?$"
|
44
|
+
|
19
45
|
class << self
|
20
46
|
|
21
47
|
# Performs a search query for papers on the arXiv search API.
|
@@ -37,7 +63,7 @@ module Arx
|
|
37
63
|
document = Nokogiri::XML(open ENDPOINT + query.to_s + '&max_results=10000').remove_namespaces!
|
38
64
|
|
39
65
|
results = Paper.parse(document, single: false).reject {|paper| paper.id.empty?}
|
40
|
-
raise MissingPaper.new(ids.first) if results.empty? && ids.size == 1
|
66
|
+
raise Error::MissingPaper.new(ids.first) if results.empty? && ids.size == 1
|
41
67
|
ids.size == 1 && results.size == 1 ? results.first : results
|
42
68
|
end
|
43
69
|
|
data/lib/arx/cleaner.rb
CHANGED
data/lib/arx/entities/author.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'happymapper'
|
2
|
-
require 'arx/cleaner'
|
3
|
-
|
4
1
|
module Arx
|
5
2
|
|
6
3
|
# Entity/model representing an arXiv paper's author.
|
7
4
|
class Author
|
8
5
|
include HappyMapper
|
6
|
+
include Inspector
|
9
7
|
|
10
8
|
tag 'author'
|
11
9
|
|
@@ -25,5 +23,7 @@ module Arx
|
|
25
23
|
def affiliations?
|
26
24
|
!affiliations.empty?
|
27
25
|
end
|
26
|
+
|
27
|
+
inspector :name, :affiliations?, :affiliations
|
28
28
|
end
|
29
29
|
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'arx/categories'
|
2
|
-
require 'arx/cleaner'
|
3
|
-
|
4
1
|
module Arx
|
5
2
|
|
6
3
|
# Entity/model representing an arXiv paper's category.
|
7
4
|
class Category
|
8
5
|
include HappyMapper
|
6
|
+
include Inspector
|
9
7
|
|
10
8
|
tag 'category'
|
11
9
|
|
@@ -20,5 +18,7 @@ module Arx
|
|
20
18
|
def full_name
|
21
19
|
CATEGORIES[name]
|
22
20
|
end
|
21
|
+
|
22
|
+
inspector :name, :full_name
|
23
23
|
end
|
24
24
|
end
|
data/lib/arx/entities/link.rb
CHANGED
data/lib/arx/entities/paper.rb
CHANGED
@@ -1,21 +1,15 @@
|
|
1
|
-
require 'happymapper'
|
2
|
-
require 'arx/exceptions'
|
3
|
-
require 'arx/cleaner'
|
4
|
-
require_relative 'author'
|
5
|
-
require_relative 'category'
|
6
|
-
require_relative 'link'
|
7
|
-
|
8
1
|
module Arx
|
9
2
|
|
10
3
|
# Entity/model representing an arXiv paper.
|
11
4
|
class Paper
|
12
5
|
include HappyMapper
|
6
|
+
include Inspector
|
13
7
|
|
14
8
|
tag 'entry'
|
15
9
|
|
16
10
|
element :id, Cleaner, parser: :clean, tag: 'id'
|
17
11
|
# The identifier of the paper.
|
18
|
-
# @note This is either in {
|
12
|
+
# @note This is either in {OLD_IDENTIFIER_FORMAT} or {NEW_IDENTIFIER_FORMAT}.
|
19
13
|
# @example
|
20
14
|
# 1705.01662v1
|
21
15
|
# cond-mat/0211034
|
@@ -87,7 +81,7 @@ module Arx
|
|
87
81
|
# @!method comment
|
88
82
|
# The comment of the paper.
|
89
83
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a comment, use {comment?}
|
90
|
-
# @raise {
|
84
|
+
# @raise {Error::MissingField} If the paper does not have a comment.
|
91
85
|
# @return [String]
|
92
86
|
element :comment, Cleaner, parser: :clean, tag: 'comment'
|
93
87
|
|
@@ -98,7 +92,7 @@ module Arx
|
|
98
92
|
# @!method journal
|
99
93
|
# The journal reference of the paper.
|
100
94
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a journal reference, use {journal?}
|
101
|
-
# @raise {
|
95
|
+
# @raise {Error::MissingField} If the paper does not have a journal reference.
|
102
96
|
# @return [String]
|
103
97
|
element :journal, Cleaner, parser: :clean, tag: 'journal_ref'
|
104
98
|
|
@@ -113,7 +107,7 @@ module Arx
|
|
113
107
|
if self.send "#{optional}?"
|
114
108
|
instance_variable_get("@#{optional}")
|
115
109
|
else
|
116
|
-
raise
|
110
|
+
raise Error::MissingField.new(optional)
|
117
111
|
end
|
118
112
|
end
|
119
113
|
end
|
@@ -127,7 +121,7 @@ module Arx
|
|
127
121
|
# @!method pdf_url
|
128
122
|
# Link to the PDF version of the paper.
|
129
123
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a PDF link, use {pdf?}
|
130
|
-
# @raise {
|
124
|
+
# @raise {Error::MissingLink} If the paper does not have a PDF link.
|
131
125
|
# @return [String]
|
132
126
|
|
133
127
|
# @!method doi?
|
@@ -141,7 +135,7 @@ module Arx
|
|
141
135
|
# @see https://arxiv.org/help/jref#doi
|
142
136
|
# @see https://arxiv.org/help/prep#doi
|
143
137
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a DOI link, use {doi?}
|
144
|
-
# @raise {
|
138
|
+
# @raise {Error::MissingLink} If the paper does not have a DOI link.
|
145
139
|
# @return [String]
|
146
140
|
|
147
141
|
%i[pdf doi].each do |link_type|
|
@@ -155,9 +149,19 @@ module Arx
|
|
155
149
|
if self.send exists
|
156
150
|
links.find(&exists).href
|
157
151
|
else
|
158
|
-
raise
|
152
|
+
raise Error::MissingLink.new link_type.to_s.upcase
|
159
153
|
end
|
160
154
|
end
|
161
155
|
end
|
156
|
+
|
157
|
+
inspector *%i[
|
158
|
+
id url title summary authors
|
159
|
+
primary_category categories
|
160
|
+
publish_date last_updated revision?
|
161
|
+
comment? comment
|
162
|
+
journal? journal
|
163
|
+
pdf? pdf_url
|
164
|
+
doi? doi_url
|
165
|
+
]
|
162
166
|
end
|
163
167
|
end
|
data/lib/arx/error.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Arx
|
2
|
+
|
3
|
+
# Various arXiv-related errors.
|
4
|
+
module Error
|
5
|
+
|
6
|
+
# Custom error for missing links on an arXiv paper.
|
7
|
+
class MissingLink < StandardError
|
8
|
+
def initialize(link_type)
|
9
|
+
super "This arXiv paper does not have a #{link_type} link"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Custom error for missing fields on an arXiv paper.
|
14
|
+
class MissingField < StandardError
|
15
|
+
def initialize(field)
|
16
|
+
super "This arXiv paper is missing the `#{field}` field"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Custom error for missing arXiv papers.
|
21
|
+
class MissingPaper < StandardError
|
22
|
+
def initialize(id)
|
23
|
+
super "Couldn't find an arXiv paper with ID: #{id}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Arx
|
2
|
+
|
3
|
+
# Restricts +inspect+ to dump a whitelist of methods on an object.
|
4
|
+
# It will always provide `object_id` at a minimum.
|
5
|
+
# @private
|
6
|
+
module Inspector
|
7
|
+
|
8
|
+
# Overwrites the object's own inspect method.
|
9
|
+
def inspect
|
10
|
+
pairs = {}
|
11
|
+
|
12
|
+
self.class.inspector_fields.each do |field|
|
13
|
+
pairs[field] = self.send(field).inspect
|
14
|
+
rescue
|
15
|
+
end
|
16
|
+
|
17
|
+
"#<#{self.class.name}:#{self.object_id} #{pairs.map {|k,v| "#{k}=#{v}"}.join(", ")}>"
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# Returns the +inspected+ instance variable, or sets it if undefined.
|
22
|
+
def inspected
|
23
|
+
@inspected ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
# Defines helper +inspector_fields+ instance variable & method, and +inspector+ instance method on the target object.
|
27
|
+
# @param [Object] source An arbitrary object (the object that +includes+ the +Inspector+ module).
|
28
|
+
def included(source)
|
29
|
+
inspected << source
|
30
|
+
source.class_eval do
|
31
|
+
def self.inspector(*fields)
|
32
|
+
@inspector_fields = *fields
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.inspector_fields
|
36
|
+
@inspector_fields ||= []
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/arx/query/query.rb
CHANGED
data/lib/arx/query/validate.rb
CHANGED
@@ -1,30 +1,8 @@
|
|
1
|
-
require_relative '../categories'
|
2
|
-
|
3
1
|
module Arx
|
4
2
|
|
5
3
|
# Validations for arXiv search query fields and identifier schemes.
|
4
|
+
# @private
|
6
5
|
module Validate
|
7
|
-
|
8
|
-
# The current arxiv paper identifier scheme (1 April 2007 and onwards).
|
9
|
-
# The last block of digits can either be five digits (if the paper was published after 1501 - January 2015),
|
10
|
-
# or four digits (if the paper was published before 1501).
|
11
|
-
#
|
12
|
-
# @see https://arxiv.org/help/arxiv_identifier#new arXiv identifier (new)
|
13
|
-
# @example
|
14
|
-
# 1501.00001
|
15
|
-
# 1705.01662v1
|
16
|
-
# 1412.0135
|
17
|
-
# 0706.0001v2
|
18
|
-
NEW_IDENTIFIER_FORMAT = %r"^\d{4}\.\d{4,5}(v\d+)?$"
|
19
|
-
|
20
|
-
# The legacy arXiv paper identifier scheme (before 1 April 2007).
|
21
|
-
#
|
22
|
-
# @see https://arxiv.org/help/arxiv_identifier#old arXiv identifier (old)
|
23
|
-
# @example
|
24
|
-
# math/0309136v1
|
25
|
-
# cond-mat/0211034
|
26
|
-
OLD_IDENTIFIER_FORMAT = %r"^[a-z]+(\-[a-z]+)?\/\d{7}(v\d+)?$"
|
27
|
-
|
28
6
|
class << self
|
29
7
|
# Validates the +sortBy+ field of the query string.
|
30
8
|
#
|
data/lib/arx/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Onuonga
|
@@ -100,7 +100,8 @@ files:
|
|
100
100
|
- lib/arx/entities/category.rb
|
101
101
|
- lib/arx/entities/link.rb
|
102
102
|
- lib/arx/entities/paper.rb
|
103
|
-
- lib/arx/
|
103
|
+
- lib/arx/error.rb
|
104
|
+
- lib/arx/inspector.rb
|
104
105
|
- lib/arx/query/query.rb
|
105
106
|
- lib/arx/query/validate.rb
|
106
107
|
- lib/arx/version.rb
|
data/lib/arx/exceptions.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Arx
|
2
|
-
|
3
|
-
# Custom error for missing links on an arXiv paper.
|
4
|
-
class MissingLinkError < StandardError
|
5
|
-
def initialize(link_type)
|
6
|
-
super "This arXiv paper does not have a #{link_type} link"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
# Custom error for missing fields on an arXiv paper.
|
11
|
-
class MissingFieldError < StandardError
|
12
|
-
def initialize(field)
|
13
|
-
super "This arXiv paper is missing the `#{field}` field"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Custom error for missing arXiv papers.
|
18
|
-
class MissingPaper < StandardError
|
19
|
-
def initialize(id)
|
20
|
-
super "Couldn't find an arXiv paper with ID: #{id}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|