arx 1.1.0 → 1.2.0
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 +45 -0
- data/README.md +15 -4
- data/arx.gemspec +3 -2
- data/lib/arx.rb +1 -0
- data/lib/arx/categories.rb +30 -0
- data/lib/arx/cleaner.rb +2 -0
- data/lib/arx/entities/author.rb +40 -1
- data/lib/arx/entities/category.rb +38 -1
- data/lib/arx/entities/link.rb +1 -0
- data/lib/arx/entities/paper.rb +79 -13
- data/lib/arx/inspector.rb +2 -0
- data/lib/arx/query/query.rb +13 -1
- data/lib/arx/query/validate.rb +1 -0
- data/lib/arx/version.rb +1 -1
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9276c200c40eae1213c2d0c7222586ecdf5a398ee5df259c9f2d6791603ad7ac
|
4
|
+
data.tar.gz: 711a0abadcc65ce14b7fd6ce3bb7380fb20435b951b2461250606540f52b44ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c367c950ada3d0dc3f5c3ab3bc720632bcdf63dc2484be4ca4c2795292118db5ed787b5908cbd2026b3c0623ef00ea5d4cc9c7e8928c693da8923790088af8bf
|
7
|
+
data.tar.gz: 9fe5a7b20e69ff159df7ce897cd55335a6b4d35982732eb0fb307ee018e2490fbdbb7cde639850aae1767506737d6286e37cead7f99baea581e1dfedd4e2158b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1
|
+
# 1.2.0
|
2
|
+
|
3
|
+
#### Major changes
|
4
|
+
|
5
|
+
- Adds serialization support through the following methods ([#63](https://github.com/eonu/arx/pull/63)):
|
6
|
+
- `to_h`: Serialize into a Ruby hash (with symbol keys). Accepts a boolean argument, representing whether or not to deep-serialize nested `Author` and `Category` objects (defaults to `false`).
|
7
|
+
- `as_json`: Serialize into a Ruby hash which is also a valid JSON hash.
|
8
|
+
- `to_json`: Serialize into a valid JSON string.
|
9
|
+
- Remove version filter from query ID list. ([#69](https://github.com/eonu/arx/pull/69))
|
10
|
+
> Previously, all of the following would return the latest paper, `1807.06918v2`:
|
11
|
+
> ```ruby
|
12
|
+
> Arx.get('1807.06918').version #=> 2
|
13
|
+
> Arx.get('1807.06918v1').version #=> 2
|
14
|
+
> Arx.get('1807.06918v2').version #=> 2
|
15
|
+
> ```
|
16
|
+
|
17
|
+
- Adds `ATTRIBUTES` constant for `Paper`, `Author` and `Category` entities, as a list of which attributes are available for the entity. ([#63](https://github.com/eonu/arx/pull/63))
|
18
|
+
- Remove key-word arguments from `Paper#id` and `Paper#url`. ([#70](https://github.com/eonu/arx/pull/70))
|
19
|
+
> Previously, `Paper#id` and `Paper#url` accepted a `version` key-word argument, which was a boolean variable indicating whether or not to include the version number in the ID or URL.
|
20
|
+
>
|
21
|
+
> This has now been changed to a regular argument, which still defaults to `false`.
|
22
|
+
> ```ruby
|
23
|
+
> paper = Arx.get('cond-mat/9609089')
|
24
|
+
>
|
25
|
+
> # Old (no longer works)
|
26
|
+
> paper.id(version: true)
|
27
|
+
> paper.url(version: true)
|
28
|
+
>
|
29
|
+
> # New
|
30
|
+
> paper.id(true) #=> "cond-mat/9609089v1"
|
31
|
+
> paper.url(true) #=> "http://arxiv.org/abs/cond-mat/9609089v1"
|
32
|
+
> ```
|
33
|
+
|
34
|
+
- Add equality operator (`==`) to entities. ([#68](https://github.com/eonu/arx/pull/68))
|
35
|
+
|
36
|
+
#### Minor changes
|
37
|
+
|
38
|
+
- Add more category mappings to `CATEGORIES`. ([#71](https://github.com/eonu/arx/pull/71))
|
39
|
+
- Add licensing information to `README.md` under the *Acknowledgements* section. ([#66](https://github.com/eonu/arx/pull/66))
|
40
|
+
- Add `yard` development dependency for documentation. ([#65](https://github.com/eonu/arx/pull/65))
|
41
|
+
- Make documentation spacing uniform. ([#64](https://github.com/eonu/arx/pull/64))
|
42
|
+
- Coveralls:
|
43
|
+
- `coveralls` [`= 0.8.22` to `= 0.8.23`] ([#62](https://github.com/eonu/arx/pull/62))
|
44
|
+
- `thor` [`~> 0.19.4` to `~> 0.20.3`] ([#67](https://github.com/eonu/arx/pull/67))
|
45
|
+
|
1
46
|
# 1.1.0
|
2
47
|
|
3
48
|
#### Major changes
|
data/README.md
CHANGED
@@ -310,11 +310,11 @@ paper = Arx('1809.09415')
|
|
310
310
|
|
311
311
|
paper.id
|
312
312
|
#=> "1809.09415"
|
313
|
-
paper.id(
|
313
|
+
paper.id(true)
|
314
314
|
#=> "1809.09415v1"
|
315
315
|
paper.url
|
316
316
|
#=> "http://arxiv.org/abs/1809.09415"
|
317
|
-
paper.url(
|
317
|
+
paper.url(true)
|
318
318
|
#=> "http://arxiv.org/abs/1809.09415v1"
|
319
319
|
paper.version
|
320
320
|
#=> 1
|
@@ -398,12 +398,23 @@ category.full_name
|
|
398
398
|
#=> "Condensed Matter"
|
399
399
|
```
|
400
400
|
|
401
|
-
#
|
401
|
+
# Acknowledgements
|
402
402
|
|
403
403
|
A large portion of this library is based on the brilliant work done by [Scholastica](https://github.com/scholastica) in their [`arxiv`](https://github.com/scholastica/arxiv) gem for retrieving individual papers from arXiv through the search API.
|
404
404
|
|
405
405
|
Arx was created mostly due to the seemingly inactive nature of Scholastica's repository. Additionally, it would have been infeasible to contribute such large changes to an already well-established gem, especially since https://scholasticahq.com/ appears to be dependent upon this gem.
|
406
406
|
|
407
|
+
Nevertheless, a special thanks goes out to Scholastica for providing the influence for Arx.
|
408
|
+
|
407
409
|
---
|
408
410
|
|
409
|
-
|
411
|
+
<p align="center">
|
412
|
+
<b>Arx</b> © 2019-2020, Edwin Onuonga - Released under the <a href="http://mit-license.org/">MIT</a> License.<br/>
|
413
|
+
<em>Authored and maintained by Edwin Onuonga.</em>
|
414
|
+
|
415
|
+
<p align="center">
|
416
|
+
<a href="https://eonu.net">eonu.net</a> ·
|
417
|
+
GitHub: <a href="https://github.com/eonu">@eonu</a> ·
|
418
|
+
Email: <a href="mailto:ed@eonu.net">ed@eonu.net</a>
|
419
|
+
</p>
|
420
|
+
</p>
|
data/arx.gemspec
CHANGED
@@ -23,9 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '>= 1.17'
|
25
25
|
spec.add_development_dependency 'rake', '~> 12.3'
|
26
|
-
spec.add_development_dependency 'thor', '~> 0.
|
26
|
+
spec.add_development_dependency 'thor', '~> 0.20.3'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
28
|
-
spec.add_development_dependency 'coveralls', '0.8.
|
28
|
+
spec.add_development_dependency 'coveralls', '0.8.23'
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.10'
|
29
30
|
|
30
31
|
spec.metadata = {
|
31
32
|
'source_code_uri' => spec.homepage,
|
data/lib/arx.rb
CHANGED
data/lib/arx/categories.rb
CHANGED
@@ -21,6 +21,14 @@ module Arx
|
|
21
21
|
'cond-mat.stat-mech' => 'Statistical Mechanics',
|
22
22
|
'cond-mat.str-el' => 'Strongly Correlated Electrons',
|
23
23
|
'cond-mat.supr-con' => 'Superconductivity',
|
24
|
+
'dis-nn' => 'Disordered Systems and Neural Networks', # cond-mat
|
25
|
+
'mes-hall' => 'Mesoscale and Nanoscale Physics', # cond-mat
|
26
|
+
'mtrl-sci' => 'Materials Science', # cond-mat
|
27
|
+
'quant-gas' => 'Quantum Gases', # cond-mat
|
28
|
+
'soft' => 'Soft Condensed Matter', # cond-mat
|
29
|
+
'stat-mech' => 'Statistical Mechanics', # cond-mat
|
30
|
+
'str-el' => 'Strongly Correlated Electrons', # cond-mat
|
31
|
+
'supr-con' => 'Superconductivity', # cond-mat
|
24
32
|
'cs' => 'Computer Science',
|
25
33
|
'cs.AI' => 'Artificial Intelligence',
|
26
34
|
'cs.AR' => 'Hardware Architecture',
|
@@ -138,6 +146,28 @@ module Arx
|
|
138
146
|
'physics.pop-ph' => 'Popular Physics',
|
139
147
|
'physics.soc-ph' => 'Physics and Society',
|
140
148
|
'physics.space-ph' => 'Space Physics',
|
149
|
+
'acc-ph' => 'Accelerator Physics', # physics
|
150
|
+
'ao-ph' => 'Atmospheric and Oceanic Physics', # physics
|
151
|
+
'app-ph' => 'Applied Physics', # physics
|
152
|
+
'atm-clus' => 'Atomic and Molecular Clusters', # physics
|
153
|
+
'atom-ph' => 'Atomic Physics', # physics
|
154
|
+
'bio-ph' => 'Biological Physics', # physics
|
155
|
+
'chem-ph' => 'Chemical Physics', # physics
|
156
|
+
'class-ph' => 'Classical Physics', # physics
|
157
|
+
'comp-ph' => 'Computational Physics', # physics
|
158
|
+
'data-an' => 'Data Analysis, Statistics and Probability', # physics
|
159
|
+
'ed-ph' => 'Physics Education', # physics
|
160
|
+
'flu-dyn' => 'Fluid Dynamics', # physics
|
161
|
+
'gen-ph' => 'General Physics', # physics
|
162
|
+
'geo-ph' => 'Geophysics', # physics
|
163
|
+
'hist-ph' => 'History and Philosophy of Physics', # physics
|
164
|
+
'ins-det' => 'Instrumentation and Detectors', # physics
|
165
|
+
'med-ph' => 'Medical Physics', # physics
|
166
|
+
'optics' => 'Optics', # physics
|
167
|
+
'plasm-ph' => 'Plasma Physics', # physics
|
168
|
+
'pop-ph' => 'Popular Physics', # physics
|
169
|
+
'soc-ph' => 'Physics and Society', # physics
|
170
|
+
'space-ph' => 'Space Physics', # physics
|
141
171
|
'q-bio' => 'Quantitative Biology',
|
142
172
|
'q-bio.BM' => 'Biomolecules',
|
143
173
|
'q-bio.CB' => 'Cell Behavior',
|
data/lib/arx/cleaner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Arx
|
2
2
|
|
3
3
|
# Class for cleaning strings.
|
4
|
+
#
|
4
5
|
# @private
|
5
6
|
class Cleaner
|
6
7
|
|
@@ -10,6 +11,7 @@ module Arx
|
|
10
11
|
class << self
|
11
12
|
|
12
13
|
# Cleans strings.
|
14
|
+
#
|
13
15
|
# @param [String] string Removes newline/return characters and multiple spaces from a string.
|
14
16
|
# @return [String] The cleaned string.
|
15
17
|
def clean(string)
|
data/lib/arx/entities/author.rb
CHANGED
@@ -5,24 +5,63 @@ module Arx
|
|
5
5
|
include HappyMapper
|
6
6
|
include Inspector
|
7
7
|
|
8
|
+
# The attributes of an arXiv paper's author.
|
9
|
+
ATTRIBUTES = %i[name affiliated? affiliations]
|
10
|
+
|
8
11
|
tag 'author'
|
9
12
|
|
10
13
|
# @!method name
|
11
14
|
# The name of the author.
|
15
|
+
#
|
12
16
|
# @return [String]
|
13
17
|
element :name, Cleaner, tag: 'name', parser: :clean
|
14
18
|
|
15
19
|
# @!method affiliations
|
16
20
|
# The author's affiliations.
|
21
|
+
#
|
17
22
|
# @return [Array<String>]
|
18
23
|
has_many :affiliations, Cleaner, tag: 'affiliation', parser: :clean
|
19
24
|
|
20
25
|
# Whether or not the author has any affiliations.
|
26
|
+
#
|
21
27
|
# @return [Boolean]
|
22
28
|
def affiliated?
|
23
29
|
!affiliations.empty?
|
24
30
|
end
|
25
31
|
|
26
|
-
|
32
|
+
# Serializes the {Author} object into a +Hash+.
|
33
|
+
#
|
34
|
+
# @return [Hash]
|
35
|
+
def to_h
|
36
|
+
Hash[*ATTRIBUTES.map {|_| [_, send(_)]}.flatten(1)]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Serializes the {Author} object into a valid JSON hash.
|
40
|
+
#
|
41
|
+
# @return [Hash] The resulting JSON hash.
|
42
|
+
def as_json
|
43
|
+
JSON.parse to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
# Serializes the {Author} object into a valid JSON string.
|
47
|
+
#
|
48
|
+
# @return [String] The resulting JSON string.
|
49
|
+
def to_json
|
50
|
+
to_h.to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
# Equality check against another author.
|
54
|
+
#
|
55
|
+
# @note This only performs a basic equality check between the authors' names.
|
56
|
+
# @param author [Author] The author to compare against.
|
57
|
+
def ==(author)
|
58
|
+
if author.is_a? Author
|
59
|
+
name == author.name
|
60
|
+
else
|
61
|
+
false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
inspector *ATTRIBUTES
|
27
66
|
end
|
28
67
|
end
|
@@ -5,20 +5,57 @@ module Arx
|
|
5
5
|
include HappyMapper
|
6
6
|
include Inspector
|
7
7
|
|
8
|
+
# The attributes of an arXiv paper's category.
|
9
|
+
ATTRIBUTES = %i[name full_name]
|
10
|
+
|
8
11
|
tag 'category'
|
9
12
|
|
10
13
|
# @!method name
|
11
14
|
# The abbreviated name of the category.
|
15
|
+
#
|
12
16
|
# @return [String]
|
13
17
|
attribute :name, Cleaner, parser: :clean, tag: 'term'
|
14
18
|
|
15
19
|
# The full name of the category.
|
20
|
+
#
|
16
21
|
# @see CATEGORIES
|
17
22
|
# @return [String]
|
18
23
|
def full_name
|
19
24
|
CATEGORIES[name]
|
20
25
|
end
|
21
26
|
|
22
|
-
|
27
|
+
# Serializes the {Category} object into a +Hash+.
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
def to_h
|
31
|
+
Hash[*ATTRIBUTES.map {|_| [_, send(_)]}.flatten(1)]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Serializes the {Category} object into a valid JSON hash.
|
35
|
+
#
|
36
|
+
# @return [Hash] The resulting JSON hash.
|
37
|
+
def as_json
|
38
|
+
JSON.parse to_json
|
39
|
+
end
|
40
|
+
|
41
|
+
# Serializes the {Category} object into a valid JSON string.
|
42
|
+
#
|
43
|
+
# @return [String] The resulting JSON string.
|
44
|
+
def to_json
|
45
|
+
to_h.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
# Equality check against another category.
|
49
|
+
#
|
50
|
+
# @param category [Category] The category to compare against.
|
51
|
+
def ==(category)
|
52
|
+
if category.is_a? Category
|
53
|
+
name == category.name
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
inspector *ATTRIBUTES
|
23
60
|
end
|
24
61
|
end
|
data/lib/arx/entities/link.rb
CHANGED
data/lib/arx/entities/paper.rb
CHANGED
@@ -5,37 +5,54 @@ module Arx
|
|
5
5
|
include HappyMapper
|
6
6
|
include Inspector
|
7
7
|
|
8
|
+
# The attributes of an arXiv paper.
|
9
|
+
# @note {comment}, {journal}, {pdf_url} and {doi_url} may raise errors when called.
|
10
|
+
ATTRIBUTES = %i[
|
11
|
+
id url version revision?
|
12
|
+
title summary authors
|
13
|
+
primary_category categories
|
14
|
+
published_at updated_at
|
15
|
+
comment? comment
|
16
|
+
journal? journal
|
17
|
+
pdf? pdf_url
|
18
|
+
doi? doi_url
|
19
|
+
]
|
20
|
+
|
8
21
|
tag 'entry'
|
9
22
|
|
10
23
|
element :id, Cleaner, parser: :clean, tag: 'id'
|
11
24
|
# The identifier of the paper.
|
25
|
+
#
|
12
26
|
# @note This is either in {OLD_IDENTIFIER_FORMAT} or {NEW_IDENTIFIER_FORMAT}.
|
13
27
|
# @example
|
14
28
|
# 1705.01662v1
|
15
29
|
# cond-mat/0211034
|
16
30
|
# @param version [Boolean] Whether or not to include the paper's version.
|
17
31
|
# @return [String] The paper's identifier.
|
18
|
-
def id(version
|
32
|
+
def id(version = false)
|
19
33
|
Cleaner.extract_id @id, version: version
|
20
34
|
end
|
21
35
|
|
22
36
|
# The URL of the paper on the arXiv website.
|
37
|
+
#
|
23
38
|
# @example
|
24
39
|
# http://arxiv.org/abs/1705.01662v1
|
25
40
|
# http://arxiv.org/abs/cond-mat/0211034
|
26
41
|
# @param version [Boolean] Whether or not to include the paper's version.
|
27
42
|
# @return [String] The paper's arXiv URL.
|
28
|
-
def url(version
|
29
|
-
"http://arxiv.org/abs/#{id version
|
43
|
+
def url(version = false)
|
44
|
+
"http://arxiv.org/abs/#{id version}"
|
30
45
|
end
|
31
46
|
|
32
47
|
# The version of the paper.
|
48
|
+
#
|
33
49
|
# @return [Integer] The paper's version.
|
34
50
|
def version
|
35
51
|
Cleaner.extract_version @id
|
36
52
|
end
|
37
53
|
|
38
54
|
# Whether the paper is a revision or not.
|
55
|
+
#
|
39
56
|
# @note A paper is a revision if its {version} is greater than 1.
|
40
57
|
# @return [Boolean]
|
41
58
|
def revision?
|
@@ -44,47 +61,56 @@ module Arx
|
|
44
61
|
|
45
62
|
# @!method updated_at
|
46
63
|
# The date that the paper was last updated.
|
64
|
+
#
|
47
65
|
# @return [DateTime]
|
48
66
|
element :updated_at, DateTime, tag: 'updated'
|
49
67
|
|
50
68
|
# @!method published_at
|
51
69
|
# The original publish/submission date of the paper.
|
70
|
+
#
|
52
71
|
# @return [DateTime]
|
53
72
|
element :published_at, DateTime, tag: 'published'
|
54
73
|
|
55
74
|
# @!method title
|
56
75
|
# The title of the paper.
|
76
|
+
#
|
57
77
|
# @return [DateTime]
|
58
78
|
element :title, Cleaner, parser: :clean, tag: 'title'
|
59
79
|
|
60
80
|
# @!method authors
|
61
81
|
# The authors of the paper.
|
82
|
+
#
|
62
83
|
# @return [Array<Author>]
|
63
84
|
has_many :authors, Author, tag: 'author'
|
64
85
|
|
65
86
|
# @!method primary_category
|
66
87
|
# The primary category of the paper.
|
88
|
+
#
|
67
89
|
# @return [Category]
|
68
90
|
element :primary_category, Category, tag: 'primary_category'
|
69
91
|
alias_method :category, :primary_category
|
70
92
|
|
71
93
|
# @!method categories
|
72
94
|
# The categories of the paper.
|
95
|
+
#
|
73
96
|
# @return [Array<Category>]
|
74
97
|
has_many :categories, Category, tag: 'category'
|
75
98
|
|
76
99
|
# @!method summary
|
77
100
|
# The summary (or abstract) of the paper.
|
101
|
+
#
|
78
102
|
# @return [String]
|
79
103
|
element :summary, Cleaner, parser: :clean, tag: 'summary'
|
80
104
|
alias_method :abstract, :summary
|
81
105
|
|
82
106
|
# @!method comment?
|
83
107
|
# Whether or not the paper has a comment.
|
108
|
+
#
|
84
109
|
# @return [Boolean]
|
85
110
|
|
86
111
|
# @!method comment
|
87
112
|
# The comment of the paper.
|
113
|
+
#
|
88
114
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a comment, use {comment?}
|
89
115
|
# @raise {Error::MissingField} If the paper does not have a comment.
|
90
116
|
# @return [String]
|
@@ -92,10 +118,12 @@ module Arx
|
|
92
118
|
|
93
119
|
# @!method journal?
|
94
120
|
# Whether or not the paper has a journal reference.
|
121
|
+
#
|
95
122
|
# @return [Boolean]
|
96
123
|
|
97
124
|
# @!method journal
|
98
125
|
# The journal reference of the paper.
|
126
|
+
#
|
99
127
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a journal reference, use {journal?}
|
100
128
|
# @raise {Error::MissingField} If the paper does not have a journal reference.
|
101
129
|
# @return [String]
|
@@ -121,22 +149,26 @@ module Arx
|
|
121
149
|
|
122
150
|
# @!method pdf?
|
123
151
|
# Whether or not the paper has a PDF link.
|
152
|
+
#
|
124
153
|
# @return [Boolean]
|
125
154
|
|
126
155
|
# @!method pdf_url
|
127
156
|
# Link to the PDF version of the paper.
|
157
|
+
#
|
128
158
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a PDF link, use {pdf?}
|
129
159
|
# @raise {Error::MissingLink} If the paper does not have a PDF link.
|
130
160
|
# @return [String]
|
131
161
|
|
132
162
|
# @!method doi?
|
133
163
|
# Whether or not the paper has a DOI (Digital Object Identifier) link.
|
164
|
+
#
|
134
165
|
# @see https://arxiv.org/help/jref#doi
|
135
166
|
# @see https://arxiv.org/help/prep#doi
|
136
167
|
# @return [Boolean]
|
137
168
|
|
138
169
|
# @!method doi_url
|
139
170
|
# Link to the DOI (Digital Object Identifier) of the paper.
|
171
|
+
#
|
140
172
|
# @see https://arxiv.org/help/jref#doi
|
141
173
|
# @see https://arxiv.org/help/prep#doi
|
142
174
|
# @note This is an optional metadata field on an arXiv paper. To check whether the paper has a DOI link, use {doi?}
|
@@ -159,15 +191,49 @@ module Arx
|
|
159
191
|
end
|
160
192
|
end
|
161
193
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
194
|
+
# Serializes the {Paper} object into a +Hash+.
|
195
|
+
#
|
196
|
+
# @param deep [Boolean] Whether to deep-serialize {Author} and {Category} objects.
|
197
|
+
# @return [Hash]
|
198
|
+
def to_h(deep = false)
|
199
|
+
Hash[*ATTRIBUTES.map {|_| [_, send(_)] rescue nil}.compact.flatten(1)].tap do |hash|
|
200
|
+
if deep
|
201
|
+
hash[:authors].map! &:to_h
|
202
|
+
hash[:categories].map! &:to_h
|
203
|
+
hash[:primary_category] = hash[:primary_category].to_h
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Serializes the {Paper} object into a valid JSON hash.
|
209
|
+
#
|
210
|
+
# @note Deep-serializes {Author} and {Category} objects.
|
211
|
+
# @return [Hash] The resulting JSON hash.
|
212
|
+
def as_json
|
213
|
+
JSON.parse to_json
|
214
|
+
end
|
215
|
+
|
216
|
+
# Serializes the {Paper} object into a valid JSON string.
|
217
|
+
#
|
218
|
+
# @note Deep-serializes {Author} and {Category} objects.
|
219
|
+
# @return [String] The resulting JSON string.
|
220
|
+
def to_json
|
221
|
+
to_h(true).to_json
|
222
|
+
end
|
223
|
+
|
224
|
+
# Equality check against another paper.
|
225
|
+
#
|
226
|
+
# @note This only performs a basic equality check between the papers' identifiers (disregarding version).
|
227
|
+
# This means that a different version of the same paper will be viewed as equal.
|
228
|
+
# @param paper [Paper] The paper to compare against.
|
229
|
+
def ==(paper)
|
230
|
+
if paper.is_a? Paper
|
231
|
+
id == paper.id
|
232
|
+
else
|
233
|
+
false
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
inspector *ATTRIBUTES
|
172
238
|
end
|
173
239
|
end
|
data/lib/arx/inspector.rb
CHANGED
@@ -2,6 +2,7 @@ module Arx
|
|
2
2
|
|
3
3
|
# Restricts +inspect+ to dump a whitelist of methods on an object.
|
4
4
|
# It will always provide `object_id` at a minimum.
|
5
|
+
#
|
5
6
|
# @private
|
6
7
|
module Inspector
|
7
8
|
|
@@ -24,6 +25,7 @@ module Arx
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Defines helper +inspector_fields+ instance variable & method, and +inspector+ instance method on the target object.
|
28
|
+
#
|
27
29
|
# @param [Object] source An arbitrary object (the object that +includes+ the +Inspector+ module).
|
28
30
|
def included(source)
|
29
31
|
inspected << source
|
data/lib/arx/query/query.rb
CHANGED
@@ -23,6 +23,7 @@ module Arx
|
|
23
23
|
}
|
24
24
|
|
25
25
|
# Supported fields for the search queries made to the arXiv search API.
|
26
|
+
#
|
26
27
|
# @see https://arxiv.org/help/prep arXiv metadata fields
|
27
28
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual (query details)
|
28
29
|
FIELDS = {
|
@@ -66,7 +67,7 @@ module Arx
|
|
66
67
|
|
67
68
|
ids.flatten!
|
68
69
|
unless ids.empty?
|
69
|
-
ids.map!
|
70
|
+
ids.map! {|id| Cleaner.extract_id(id, version: true)}
|
70
71
|
@query << "&#{PARAMS[:id_list]}=#{ids * ','}"
|
71
72
|
end
|
72
73
|
|
@@ -75,16 +76,19 @@ module Arx
|
|
75
76
|
|
76
77
|
# @!method and
|
77
78
|
# Logical conjunction (+AND+) of subqueries.
|
79
|
+
#
|
78
80
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
79
81
|
# @return [self]
|
80
82
|
|
81
83
|
# @!method and_not
|
82
84
|
# Logical negated conjunction (+ANDNOT+) of subqueries.
|
85
|
+
#
|
83
86
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
84
87
|
# @return [self]
|
85
88
|
|
86
89
|
# @!method or
|
87
90
|
# Logical disjunction (+OR+) of subqueries.
|
91
|
+
#
|
88
92
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
89
93
|
# @return [self]
|
90
94
|
|
@@ -94,6 +98,7 @@ module Arx
|
|
94
98
|
|
95
99
|
# @!method title(*values, exact: true, connective: :and)
|
96
100
|
# Search for papers by {https://arxiv.org/help/prep#title title}.
|
101
|
+
#
|
97
102
|
# @param values [Array<String>] Title(s) of papers to search for.
|
98
103
|
# @param exact [Boolean] Whether to search for an exact match of the title(s).
|
99
104
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -101,6 +106,7 @@ module Arx
|
|
101
106
|
|
102
107
|
# @!method author(*values, exact: true, connective: :and)
|
103
108
|
# Search for papers by {https://arxiv.org/help/prep#author author}.
|
109
|
+
#
|
104
110
|
# @param values [Array<String>] Author(s) of papers to search for.
|
105
111
|
# @param exact [Boolean] Whether to search for an exact match of the author's name(s).
|
106
112
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -108,6 +114,7 @@ module Arx
|
|
108
114
|
|
109
115
|
# @!method abstract(*values, exact: true, connective: :and)
|
110
116
|
# Search for papers by {https://arxiv.org/help/prep#abstract abstract}.
|
117
|
+
#
|
111
118
|
# @param values [Array<String>] Abstract(s) of papers to search for.
|
112
119
|
# @param exact [Boolean] Whether to search for an exact match of the abstract(s).
|
113
120
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -115,6 +122,7 @@ module Arx
|
|
115
122
|
|
116
123
|
# @!method comment(*values, exact: true, connective: :and)
|
117
124
|
# Search for papers by {https://arxiv.org/help/prep#comments comment}.
|
125
|
+
#
|
118
126
|
# @param values [Array<String>] Comment(s) of papers to search for.
|
119
127
|
# @param exact [Boolean] Whether to search for an exact match of the comment(s).
|
120
128
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -122,6 +130,7 @@ module Arx
|
|
122
130
|
|
123
131
|
# @!method journal(*values, exact: true, connective: :and)
|
124
132
|
# Search for papers by {https://arxiv.org/help/prep#journal journal reference}.
|
133
|
+
#
|
125
134
|
# @param values [Array<String>] Journal reference(s) of papers to search for.
|
126
135
|
# @param exact [Boolean] Whether to search for an exact match of the journal refernece(s).
|
127
136
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -129,18 +138,21 @@ module Arx
|
|
129
138
|
|
130
139
|
# @!method category(*values, connective: :and)
|
131
140
|
# Search for papers by {https://arxiv.org/help/prep#category category}.
|
141
|
+
#
|
132
142
|
# @param values [Array<String>] Category(s) of papers to search for.
|
133
143
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
134
144
|
# @return [self]
|
135
145
|
|
136
146
|
# @!method report(*values, connective: :and)
|
137
147
|
# Search for papers by {https://arxiv.org/help/prep#report report number}.
|
148
|
+
#
|
138
149
|
# @param values [Array<String>] Report number(s) of papers to search for.
|
139
150
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
140
151
|
# @return [self]
|
141
152
|
|
142
153
|
# @!method all(*values, exact: true, connective: :and)
|
143
154
|
# Search for papers by all fields (see {FIELDS}).
|
155
|
+
#
|
144
156
|
# @param values [Array<String>] Field value(s) of papers to search for.
|
145
157
|
# @param exact [Boolean] Whether to search for an exact match of the comment(s).
|
146
158
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
data/lib/arx/query/validate.rb
CHANGED
data/lib/arx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Onuonga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.20.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.20.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,34 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.8.
|
103
|
+
version: 0.8.23
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.8.
|
110
|
+
version: 0.8.23
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.9.10
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0.9'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.9.10
|
111
131
|
description:
|
112
132
|
email:
|
113
133
|
- ed@eonu.net
|