arx 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -28
- data/README.md +69 -21
- data/lib/arx.rb +22 -6
- data/lib/arx/entities/author.rb +8 -0
- data/lib/arx/entities/category.rb +8 -0
- data/lib/arx/entities/paper.rb +12 -0
- data/lib/arx/query/query.rb +37 -13
- data/lib/arx/query/validate.rb +12 -0
- data/lib/arx/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6530eb98d35658cacb54768f8a310e1c8f0ca7ecaf20fd816624e25ef69bd92a
|
4
|
+
data.tar.gz: 0e62e301e3c5eee07403f99c9b0cd0503716afc59b45b1a92404286ccbf58ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d287f54c864acb1e03e9993e76f5b726ac1e3a382b3543b13f3bff8fb762464018d289c7645fbf2ac7047670f232e0e5580addcb06bf9fa5dbc92ec75e21872d
|
7
|
+
data.tar.gz: 8b4909da8e6fa1966b7acc78cef78164da9efda370cff81fbbbd90a49f525d496dd1a0a598b085c61fd4158aa077ba341106d35e937c748fc90c0f081d2b9766
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,28 @@
|
|
1
|
-
|
1
|
+
## 1.3.0
|
2
2
|
|
3
|
-
|
3
|
+
### Major changes
|
4
|
+
|
5
|
+
- Add support for paging. ([#92](https://github.com/eonu/arx/pull/92) by @xuanxu)
|
6
|
+
- Allow searching by `last_updated_date`. ([#93](https://github.com/eonu/arx/pull/93) by @xuanxu)
|
7
|
+
- Add `submitted_at` for submission date querying. ([#97](https://github.com/eonu/arx/pull/97))<br/>
|
8
|
+
This also changes `last_updated_date` from #93 to `updated_at`, and similarly for the `last_updated` and `date_submitted` [sort-by criteria](https://github.com/eonu/arx/blob/3d093658579fb2d99b92f0feedb2aa790a22e2c8/lib/arx/query/query.rb#L43).
|
9
|
+
|
10
|
+
### Minor changes
|
11
|
+
|
12
|
+
- Update `Arx()` to match new `Arx.search` signature (from #92). ([#94](https://github.com/eonu/arx/pull/94))
|
13
|
+
- Change incorrect `lastUpdated` sort-by criterion to `lastUpdatedDate`. ([#96](https://github.com/eonu/arx/pull/96))
|
14
|
+
- Add `to_s` methods for `Arx::Paper`, `Arx::Author` and `Arx::Category`. ([#99](https://github.com/eonu/arx/pull/99))
|
15
|
+
- Add fix for JSON warning in Ruby >=2.7. ([#101](https://github.com/eonu/arx/pull/101))
|
16
|
+
- Add contributors section to `README.md`. ([#102](https://github.com/eonu/arx/pull/102))
|
17
|
+
|
18
|
+
## 1.2.1
|
19
|
+
|
20
|
+
### Major changes
|
4
21
|
|
5
22
|
- Add support for saving PDFs with `Paper#save` (see #81). ([#90](https://github.com/eonu/arx/pull/90))
|
6
23
|
- Change gem Ruby version specifier from `~> 2.5` to `>= 2.5`. ([#86](https://github.com/eonu/arx/pull/86))
|
7
24
|
|
8
|
-
|
25
|
+
### Minor changes
|
9
26
|
|
10
27
|
- Remove arXiv logo from `README.md`. ([#87](https://github.com/eonu/arx/pull/87))
|
11
28
|
- Use `URI.open` instead of `Kernel.open` (see #82). ([#86](https://github.com/eonu/arx/pull/86))
|
@@ -16,9 +33,9 @@
|
|
16
33
|
- Update specs using paper `1710.02185` to account for revision and acceptance by journal (_congratulations!_). ([#76](https://github.com/eonu/arx/pull/76))
|
17
34
|
- Update email address in `LICENSE.md`. ([#73](https://github.com/eonu/arx/pull/73))
|
18
35
|
|
19
|
-
|
36
|
+
## 1.2.0
|
20
37
|
|
21
|
-
|
38
|
+
### Major changes
|
22
39
|
|
23
40
|
- Adds serialization support through the following methods ([#63](https://github.com/eonu/arx/pull/63)):
|
24
41
|
- `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`).
|
@@ -51,7 +68,7 @@
|
|
51
68
|
|
52
69
|
- Add equality operator (`==`) to entities. ([#68](https://github.com/eonu/arx/pull/68))
|
53
70
|
|
54
|
-
|
71
|
+
### Minor changes
|
55
72
|
|
56
73
|
- Add more category mappings to `CATEGORIES`. ([#71](https://github.com/eonu/arx/pull/71))
|
57
74
|
- Add licensing information to `README.md` under the *Acknowledgements* section. ([#66](https://github.com/eonu/arx/pull/66))
|
@@ -61,15 +78,15 @@
|
|
61
78
|
- `coveralls` [`= 0.8.22` to `= 0.8.23`] ([#62](https://github.com/eonu/arx/pull/62))
|
62
79
|
- `thor` [`~> 0.19.4` to `~> 0.20.3`] ([#67](https://github.com/eonu/arx/pull/67))
|
63
80
|
|
64
|
-
|
81
|
+
## 1.1.0
|
65
82
|
|
66
|
-
|
83
|
+
### Major changes
|
67
84
|
|
68
85
|
- Change `bundler` requirement to `>= 1.17` in `arx.gemspec`. ([#53](https://github.com/eonu/arx/pull/53))
|
69
86
|
- Remove `Arx.find` alias of `Arx.search`. ([#57](https://github.com/eonu/arx/pull/57))
|
70
87
|
- Add `Query#group` for subquery grouping support. ([#59](https://github.com/eonu/arx/pull/59))
|
71
88
|
|
72
|
-
|
89
|
+
### Minor changes
|
73
90
|
|
74
91
|
- Add contributing guidelines (`CONTRIBUTING.md`). ([#48](https://github.com/eonu/arx/pull/48))
|
75
92
|
- Add issue templates to `./github/ISSUE_TEMPLATE` for ([#49](https://github.com/eonu/arx/pull/49), [#54](https://github.com/eonu/arx/pull/54), [#55](https://github.com/eonu/arx/pull/55)):
|
@@ -86,14 +103,14 @@
|
|
86
103
|
- Add `bin/console` for gem debugging. ([#60](https://github.com/eonu/arx/pull/60))
|
87
104
|
- Modify `gem:debug` rake task to run `bin/console`. ([#60](https://github.com/eonu/arx/pull/60))
|
88
105
|
|
89
|
-
|
106
|
+
## 1.0.1
|
90
107
|
|
91
|
-
|
108
|
+
### Major changes
|
92
109
|
|
93
110
|
- Add cases to handle `nil` query returns. ([#45](https://github.com/eonu/arx/pull/45))
|
94
111
|
- Add support for the `coveralls` gem (`.coveralls.yml` configuration file). ([#42](https://github.com/eonu/arx/pull/42))
|
95
112
|
|
96
|
-
|
113
|
+
### Minor changes
|
97
114
|
|
98
115
|
- Add code coverage badge to `README.md`. ([#42](https://github.com/eonu/arx/pull/42))
|
99
116
|
- Remove documentation badge from top of `README.md`. ([#42](https://github.com/eonu/arx/pull/42))
|
@@ -102,9 +119,9 @@
|
|
102
119
|
- Add `/coverage/` directory to `.gitignore`. ([#45](https://github.com/eonu/arx/pull/45))
|
103
120
|
- Remove version numbers from paper identifiers in error message in `README.md`. ([#46](https://github.com/eonu/arx/pull/46))
|
104
121
|
|
105
|
-
|
122
|
+
## 1.0.0
|
106
123
|
|
107
|
-
|
124
|
+
### Major changes
|
108
125
|
|
109
126
|
- Change `Query` connective instance methods ([#38](https://github.com/eonu/arx/pull/38)):
|
110
127
|
- `#&` -> `#and`
|
@@ -116,15 +133,15 @@
|
|
116
133
|
- Redefine `Arx.search` to user `Paper.parse`'s `search` key-word argument. ([#40](https://github.com/eonu/arx/pull/40))
|
117
134
|
- Implement all tests. ([#40](https://github.com/eonu/arx/pull/40))
|
118
135
|
|
119
|
-
|
136
|
+
### Minor changes
|
120
137
|
|
121
138
|
- Change declared regular expression literals from `%r""` to standard `//`. ([#39](https://github.com/eonu/arx/pull/39))
|
122
139
|
- Remove `#extract_id` from `Query` and use `Cleaner.extract_id` instead. ([#39](https://github.com/eonu/arx/pull/39))
|
123
140
|
- Redefine `Paper#revision?` to use the new `#version` instead of `#updated_at` and`#published_at`. ([#39](https://github.com/eonu/arx/pull/39))
|
124
141
|
|
125
|
-
|
142
|
+
## 0.3.2
|
126
143
|
|
127
|
-
|
144
|
+
### Major changes
|
128
145
|
|
129
146
|
- Add `Paper#category` alias for `Paper#primary_category`. ([#34](https://github.com/eonu/arx/pull/34))
|
130
147
|
- Change `Author#affiliations?` to `Author#affiliated?`. ([#34](https://github.com/eonu/arx/pull/34))
|
@@ -135,47 +152,47 @@
|
|
135
152
|
- Add `gem:release` rake task for preparing gem releases. ([#36](https://github.com/eonu/arx/pull/36))
|
136
153
|
- Add `thor` gem development dependency. ([#36](https://github.com/eonu/arx/pull/36))
|
137
154
|
|
138
|
-
|
155
|
+
### Minor changes
|
139
156
|
|
140
157
|
- Update documentation links to `rubydoc.info`'s GitHub service. ([#30](https://github.com/eonu/arx/pull/30))
|
141
158
|
- Add email address to `LICENSE`. ([#31](https://github.com/eonu/arx/pull/31))
|
142
159
|
- Improve `Error::MissingField` and `Error::MissingLink` error messages. ([#35](https://github.com/eonu/arx/pull/35))
|
143
160
|
|
144
|
-
|
161
|
+
## 0.3.1
|
145
162
|
|
146
|
-
|
163
|
+
### Major changes
|
147
164
|
|
148
165
|
- Add `.yardopts` for document generation configuration. ([#26](https://github.com/eonu/arx/pull/26))
|
149
166
|
- Namespace errors in `Arx::Error` module and remove `Error` prefix from error classes. ([#26](https://github.com/eonu/arx/pull/26))
|
150
167
|
- Move identifier format regular expression constant definitions from `Arx::Validate` to top-level namespace `Arx`. ([#26](https://github.com/eonu/arx/pull/26))
|
151
168
|
|
152
|
-
|
169
|
+
### Minor changes
|
153
170
|
|
154
171
|
- Rename `lib/arx/exceptions.rb` to `lib/arx/errors.rb`. ([#26](https://github.com/eonu/arx/pull/26))
|
155
172
|
- Make `Arx::Cleaner`, `Arx::Validate`, `Arx::Inspector`, `Arx::Link` private (hidden from `yard` documentation). ([#26](https://github.com/eonu/arx/pull/26))
|
156
173
|
|
157
|
-
|
174
|
+
## 0.3.0
|
158
175
|
|
159
|
-
|
176
|
+
### Major changes
|
160
177
|
|
161
178
|
- Add documentation, images, installation and usage instructions to `README.md`. ([#22](https://github.com/eonu/arx/pull/22), [#17](https://github.com/eonu/arx/pull/17))
|
162
179
|
- Allow prior construction of a search query in `Arx.search`. ([#18](https://github.com/eonu/arx/pull/18))
|
163
180
|
- Fix `Arx.search` query object yielding. ([#20](https://github.com/eonu/arx/pull/20))
|
164
181
|
|
165
|
-
|
182
|
+
### Minor changes
|
166
183
|
|
167
184
|
- Remove conditional with `block_given?` in `Arx()` method. ([#16](https://github.com/eonu/arx/pull/16))
|
168
185
|
- Remove leading ampersand (&) from search query string. ([#19](https://github.com/eonu/arx/pull/19))
|
169
186
|
- Add base paper categories and more aliases. ([#21](https://github.com/eonu/arx/pull/21))
|
170
187
|
|
171
|
-
|
188
|
+
## 0.2.0
|
172
189
|
|
173
|
-
|
190
|
+
### Major changes
|
174
191
|
|
175
192
|
- Flatten provided values in `Arx::Paper`'s field instance methods (allow an array as the `values` splat parameter). ([#5](https://github.com/eonu/arx/pull/5))
|
176
193
|
- Add `Arx.find` and `Arx.get` as aliases for `Arx.search`. ([#6](https://github.com/eonu/arx/pull/6), [#8](https://github.com/eonu/arx/pull/8))
|
177
194
|
|
178
|
-
|
195
|
+
### Minor changes
|
179
196
|
|
180
197
|
- Add `homepage` and `metadata` fields to `arx.gemspec`. ([#1](https://github.com/eonu/arx/pull/1), [#14](https://github.com/eonu/arx/pull/14))
|
181
198
|
- Specify required ruby version (`~> 2.5`) in `arx.gemspec`. ([#2](https://github.com/eonu/arx/pull/2))
|
@@ -186,6 +203,6 @@
|
|
186
203
|
- Add ruby-head version to RVM rubies in `.travis.yml`. ([#12](https://github.com/eonu/arx/pull/12))
|
187
204
|
- Remove unnecessary git-ignored files. ([#13](https://github.com/eonu/arx/pull/13), [#10](https://github.com/eonu/arx/pull/10))
|
188
205
|
|
189
|
-
|
206
|
+
## 0.1.0
|
190
207
|
|
191
208
|
Initial commit! 🎉
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Although [Scholastica](https://github.com/scholastica) offer a great [Ruby gem](
|
|
23
23
|
```ruby
|
24
24
|
require 'arx'
|
25
25
|
|
26
|
-
papers = Arx(sort_by: :
|
26
|
+
papers = Arx(sort_by: :submitted_at) do |query|
|
27
27
|
query.category('cs.FL')
|
28
28
|
query.title('Buchi Automata').and_not.author('Tomáš Babiak')
|
29
29
|
end
|
@@ -46,7 +46,7 @@ Although [Scholastica](https://github.com/scholastica) offer a great [Ruby gem](
|
|
46
46
|
## Features
|
47
47
|
|
48
48
|
- Ruby classes `Arx::Paper`, `Arx::Author` and `Arx::Category` that wrap the resulting Atom XML query result from the search API.
|
49
|
-
- Supports querying by a paper's ID, title, author(s), abstract, subject category, comment, journal reference, or
|
49
|
+
- Supports querying by a paper's ID, title, author(s), abstract, subject category, comment, journal reference, report number or last updated date.
|
50
50
|
- Provides a small DSL for writing queries.
|
51
51
|
- Supports searching fields by exact match.
|
52
52
|
|
@@ -92,13 +92,13 @@ The `Arx::Query` class provides a small DSL for writing these query strings.
|
|
92
92
|
|
93
93
|
The order in which search results are returned can be modified through the `sort_by` and `sort_order` keyword arguments (in the `Arx::Query` initializer):
|
94
94
|
|
95
|
-
- `sort_by` accepts the symbols: `:relevance`, `:
|
95
|
+
- `sort_by` accepts the symbols: `:relevance`, `:updated_at` or `:submitted_at`
|
96
96
|
|
97
97
|
- `sort_order` accepts the symbols: `:ascending` or `:descending`
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
# Sort by submission date in ascending order (earliest first)
|
101
|
-
Arx::Query.new(sort_by: :
|
101
|
+
Arx::Query.new(sort_by: :submitted_at, sort_order: :ascending)
|
102
102
|
#=> sortBy=submittedDate&sortOrder=ascending
|
103
103
|
```
|
104
104
|
|
@@ -108,6 +108,26 @@ Arx::Query.new(sort_by: :date_submitted, sort_order: :ascending)
|
|
108
108
|
Arx::Query.new #=> sortBy=relevance&sortOrder=descending
|
109
109
|
```
|
110
110
|
|
111
|
+
#### Paging
|
112
|
+
|
113
|
+
The arXiv API offers a paging mechanism that allows you to get chucks of the result set at a time. It can be used through the `start` and `max_results` keyword arguments (in the `Arx::Query` initializer):
|
114
|
+
|
115
|
+
- `start` is the index of the first returned result (using 0-based indexing)
|
116
|
+
|
117
|
+
- `max_results` is the number of results returned by the query
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
# Get results 10-29
|
121
|
+
Arx::Query.new(start: 10, max_results: 20)
|
122
|
+
#=> start=10&max_results=20
|
123
|
+
```
|
124
|
+
|
125
|
+
**Note**: The default values are those of the arXiv API: `start` defaults to `0` and `max_results` defaults to `10`:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
Arx::Query.new #=> start=0&max_results=10
|
129
|
+
```
|
130
|
+
|
111
131
|
#### Searching by ID
|
112
132
|
|
113
133
|
The arXiv search API doesn't only support searching for papers by metadata fields, but also by ID. When searching by ID, a different URL query string parameter `id_list` is used (instead of `search_query` as seen before).
|
@@ -133,14 +153,16 @@ The arXiv search API supports searches for the following paper metadata fields:
|
|
133
153
|
|
134
154
|
```ruby
|
135
155
|
FIELDS = {
|
136
|
-
title: 'ti',
|
137
|
-
author: 'au',
|
138
|
-
abstract: 'abs',
|
139
|
-
comment: 'co',
|
140
|
-
journal: 'jr',
|
141
|
-
category: 'cat',
|
142
|
-
report: 'rn',
|
143
|
-
|
156
|
+
title: 'ti', # Title
|
157
|
+
author: 'au', # Author
|
158
|
+
abstract: 'abs', # Abstract
|
159
|
+
comment: 'co', # Comment
|
160
|
+
journal: 'jr', # Journal reference
|
161
|
+
category: 'cat', # Subject category
|
162
|
+
report: 'rn', # Report number
|
163
|
+
updated_at: 'lastUpdatedDate', # Last updated date
|
164
|
+
submitted_at: 'submittedDate', # Submission date
|
165
|
+
all: 'all' # All (of the above)
|
144
166
|
}
|
145
167
|
```
|
146
168
|
|
@@ -256,7 +278,7 @@ Calling the `Arx()` method with a block allows for the construction and executio
|
|
256
278
|
|
257
279
|
```ruby
|
258
280
|
# Papers in the cs.FL category whose title contains "Buchi Automata", not authored by Tomáš Babiak
|
259
|
-
results = Arx(sort_by: :
|
281
|
+
results = Arx(sort_by: :submitted_at) do |query|
|
260
282
|
query.category('cs.FL')
|
261
283
|
query.title('Buchi Automata').and_not.author('Tomáš Babiak')
|
262
284
|
end
|
@@ -272,7 +294,7 @@ The `Arx()` method accepts a predefined `Arx::Query` object through the `query`
|
|
272
294
|
|
273
295
|
```ruby
|
274
296
|
# Papers in the cs.FL category whose title contains "Buchi Automata", not authored by Tomáš Babiak
|
275
|
-
q = Arx::Query.new(sort_by: :
|
297
|
+
q = Arx::Query.new(sort_by: :submitted_at)
|
276
298
|
q.category('cs.FL')
|
277
299
|
q.title('Buchi Automata').and_not.author('Tomáš Babiak')
|
278
300
|
|
@@ -400,7 +422,7 @@ category.full_name
|
|
400
422
|
#=> "Condensed Matter"
|
401
423
|
```
|
402
424
|
|
403
|
-
|
425
|
+
## Acknowledgements
|
404
426
|
|
405
427
|
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.
|
406
428
|
|
@@ -408,15 +430,41 @@ Arx was created mostly due to the seemingly inactive nature of Scholastica's rep
|
|
408
430
|
|
409
431
|
Nevertheless, a special thanks goes out to Scholastica for providing the influence for Arx.
|
410
432
|
|
433
|
+
## Contributors
|
434
|
+
|
435
|
+
All contributions to this repository are greatly appreciated. Contribution guidelines can be found [here](/CONTRIBUTING.md).
|
436
|
+
|
437
|
+
<table>
|
438
|
+
<thead>
|
439
|
+
<tr>
|
440
|
+
<th align="center">
|
441
|
+
<a href="https://github.com/eonu">
|
442
|
+
<img src="https://avatars0.githubusercontent.com/u/24795571?s=460&v=4" alt="Edwin Onuonga" width="60px">
|
443
|
+
<br/>eonu
|
444
|
+
<br/><sub>(Edwin Onuonga)</sub>
|
445
|
+
</a>
|
446
|
+
<br/>
|
447
|
+
<a href="mailto:ed@eonu.net">✉️</a>
|
448
|
+
<a href="https://eonu.net">🌍</a>
|
449
|
+
</th>
|
450
|
+
<th align="center">
|
451
|
+
<a href="https://github.com/xuanxu">
|
452
|
+
<img src="https://avatars.githubusercontent.com/u/6528?v=4" alt="xuanxu" width="60px">
|
453
|
+
<br/>xuanxu
|
454
|
+
<br/><sub>(Juanjo Bazán)</sub>
|
455
|
+
</a>
|
456
|
+
<br/>
|
457
|
+
<a href="jjbazan@gmail.com">✉️</a>
|
458
|
+
<a href="http://juanjobazan.com/">🌍</a>
|
459
|
+
</th>
|
460
|
+
<!-- Add more <th></th> blocks for more contributors -->
|
461
|
+
</tr>
|
462
|
+
</thead>
|
463
|
+
</table>
|
464
|
+
|
411
465
|
---
|
412
466
|
|
413
467
|
<p align="center">
|
414
468
|
<b>Arx</b> © 2019-2020, Edwin Onuonga - Released under the <a href="http://mit-license.org/">MIT</a> License.<br/>
|
415
469
|
<em>Authored and maintained by Edwin Onuonga.</em>
|
416
|
-
|
417
|
-
<p align="center">
|
418
|
-
<a href="https://eonu.net">eonu.net</a> ·
|
419
|
-
GitHub: <a href="https://github.com/eonu">@eonu</a> ·
|
420
|
-
Email: <a href="mailto:ed@eonu.net">ed@eonu.net</a>
|
421
|
-
</p>
|
422
470
|
</p>
|
data/lib/arx.rb
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'cgi'
|
4
4
|
require 'json'
|
5
|
+
|
6
|
+
# Temporary fix for JSON warning in Ruby >= 2.7.0
|
7
|
+
# See: https://github.com/flori/json/issues/399#issuecomment-734863279
|
8
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
9
|
+
module JSON
|
10
|
+
module_function
|
11
|
+
def parse(source, opts = {})
|
12
|
+
Parser.new(source, **opts).parse
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
require 'nokogiri'
|
6
18
|
require 'open-uri'
|
7
19
|
require 'happymapper'
|
@@ -47,19 +59,21 @@ module Arx
|
|
47
59
|
|
48
60
|
# Performs a search query for papers on the arXiv search API.
|
49
61
|
#
|
50
|
-
# @note The +sort_by+ and +
|
62
|
+
# @note The +sort_by+, +sort_order+, +start+ and +max_results+ arguments are ignored if passing in your own +query+.
|
51
63
|
# @param ids [Array<String>] The IDs of the arXiv papers to restrict the query to.
|
52
64
|
# @param query [Query, NilClass] Predefined search query object.
|
53
65
|
# @param sort_by [Symbol] The sorting criteria for the returned results (see {Query::SORT_BY}).
|
54
66
|
# @param sort_order [Symbol] The sorting order for the returned results (see {Query::SORT_ORDER}).
|
67
|
+
# @param start [Integer] The index of the first returned result.
|
68
|
+
# @param max_results [Integer] The number of results returned by the query
|
55
69
|
# @return [Array<Paper>, Paper] The {Paper}(s) found by the search query.
|
56
|
-
def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending)
|
57
|
-
query ||= Query.new(*ids, sort_by: sort_by, sort_order: sort_order)
|
70
|
+
def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10)
|
71
|
+
query ||= Query.new(*ids, sort_by: sort_by, sort_order: sort_order, start: start, max_results: max_results)
|
58
72
|
raise TypeError.new("Expected `query` to be an Arx::Query, got: #{query.class}") unless query.is_a? Query
|
59
73
|
|
60
74
|
yield query if block_given?
|
61
75
|
|
62
|
-
document = Nokogiri::XML(URI.open ENDPOINT + query.to_s
|
76
|
+
document = Nokogiri::XML(URI.open ENDPOINT + query.to_s).remove_namespaces!
|
63
77
|
results = Paper.parse(document, single: ids.size == 1)
|
64
78
|
|
65
79
|
if results.is_a? Paper
|
@@ -90,7 +104,9 @@ end
|
|
90
104
|
# @param query [Query, NilClass] Predefined search query object.
|
91
105
|
# @param sort_by [Symbol] The sorting criteria for the returned results (see {Arx::Query::SORT_BY}).
|
92
106
|
# @param sort_order [Symbol] The sorting order for the returned results (see {Arx::Query::SORT_ORDER}).
|
107
|
+
# @param start [Integer] The index of the first returned result.
|
108
|
+
# @param max_results [Integer] The number of results returned by the query
|
93
109
|
# @return [Array<Paper>, Paper] The {Arx::Paper}(s) found by the search query.
|
94
|
-
def Arx(*ids, query: nil, sort_by: :relevance, sort_order: :descending, &block)
|
95
|
-
Arx.search *ids, query: query, sort_by: sort_by, sort_order: sort_order, &block
|
110
|
+
def Arx(*ids, query: nil, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10, &block)
|
111
|
+
Arx.search *ids, query: query, sort_by: sort_by, sort_order: sort_order, start: start, max_results: max_results, &block
|
96
112
|
end
|
data/lib/arx/entities/author.rb
CHANGED
@@ -54,6 +54,7 @@ module Arx
|
|
54
54
|
#
|
55
55
|
# @note This only performs a basic equality check between the authors' names.
|
56
56
|
# @param author [Author] The author to compare against.
|
57
|
+
# @return [Boolean]
|
57
58
|
def ==(author)
|
58
59
|
if author.is_a? Author
|
59
60
|
name == author.name
|
@@ -62,6 +63,13 @@ module Arx
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
# A string representation of the {Author} object.
|
67
|
+
#
|
68
|
+
# @return [String]
|
69
|
+
def to_s
|
70
|
+
"Arx::Author(name: #{name}, affiliations: [#{affiliations.join(', ')}])"
|
71
|
+
end
|
72
|
+
|
65
73
|
inspector *ATTRIBUTES
|
66
74
|
end
|
67
75
|
end
|
@@ -48,6 +48,7 @@ module Arx
|
|
48
48
|
# Equality check against another category.
|
49
49
|
#
|
50
50
|
# @param category [Category] The category to compare against.
|
51
|
+
# @return [Boolean]
|
51
52
|
def ==(category)
|
52
53
|
if category.is_a? Category
|
53
54
|
name == category.name
|
@@ -56,6 +57,13 @@ module Arx
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
# A string representation of the {Category} object.
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
def to_s
|
64
|
+
"Arx::Category(name: #{name}, full_name: #{full_name || 'nil'})"
|
65
|
+
end
|
66
|
+
|
59
67
|
inspector *ATTRIBUTES
|
60
68
|
end
|
61
69
|
end
|
data/lib/arx/entities/paper.rb
CHANGED
@@ -226,6 +226,7 @@ module Arx
|
|
226
226
|
# @note This only performs a basic equality check between the papers' identifiers (disregarding version).
|
227
227
|
# This means that a different version of the same paper will be viewed as equal.
|
228
228
|
# @param paper [Paper] The paper to compare against.
|
229
|
+
# @return [Boolean]
|
229
230
|
def ==(paper)
|
230
231
|
if paper.is_a? Paper
|
231
232
|
id == paper.id
|
@@ -247,6 +248,17 @@ module Arx
|
|
247
248
|
end
|
248
249
|
end
|
249
250
|
|
251
|
+
# A string representation of the {Paper} object.
|
252
|
+
#
|
253
|
+
# @return [String]
|
254
|
+
def to_s
|
255
|
+
_id = id true
|
256
|
+
_published_at = published_at.strftime("%Y-%m-%d")
|
257
|
+
_authors = authors.map(&:name)
|
258
|
+
_authors = [*_authors.first(2), '...'] if _authors.size > 2
|
259
|
+
"Arx::Paper(id: #{_id}, published_at: #{_published_at}, authors: [#{_authors.join(', ')}], title: #{title})"
|
260
|
+
end
|
261
|
+
|
250
262
|
inspector *ATTRIBUTES
|
251
263
|
end
|
252
264
|
end
|
data/lib/arx/query/query.rb
CHANGED
@@ -12,7 +12,9 @@ module Arx
|
|
12
12
|
search_query: 'search_query',
|
13
13
|
id_list: 'id_list',
|
14
14
|
sort_by: 'sortBy',
|
15
|
-
sort_order: 'sortOrder'
|
15
|
+
sort_order: 'sortOrder',
|
16
|
+
start: 'start',
|
17
|
+
max_results: 'max_results',
|
16
18
|
}
|
17
19
|
|
18
20
|
# Logical connectives supported by the arXiv search API.
|
@@ -27,21 +29,23 @@ module Arx
|
|
27
29
|
# @see https://arxiv.org/help/prep arXiv metadata fields
|
28
30
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual (query details)
|
29
31
|
FIELDS = {
|
30
|
-
title: 'ti',
|
31
|
-
author: 'au',
|
32
|
-
abstract: 'abs',
|
33
|
-
comment: 'co',
|
34
|
-
journal: 'jr',
|
35
|
-
category: 'cat',
|
36
|
-
report: 'rn',
|
37
|
-
|
32
|
+
title: 'ti', # Title
|
33
|
+
author: 'au', # Author
|
34
|
+
abstract: 'abs', # Abstract
|
35
|
+
comment: 'co', # Comment
|
36
|
+
journal: 'jr', # Journal reference
|
37
|
+
category: 'cat', # Subject category
|
38
|
+
report: 'rn', # Report number
|
39
|
+
updated_at: 'lastUpdatedDate', # Last updated date
|
40
|
+
submitted_at: 'submittedDate', # Submission date
|
41
|
+
all: 'all' # All (of the above)
|
38
42
|
}
|
39
43
|
|
40
44
|
# Supported criteria for the +sortBy+ parameter.
|
41
45
|
SORT_BY = {
|
42
46
|
relevance: 'relevance',
|
43
|
-
|
44
|
-
|
47
|
+
updated_at: 'lastUpdatedDate',
|
48
|
+
submitted_at: 'submittedDate'
|
45
49
|
}
|
46
50
|
|
47
51
|
# Supported criteria for the +sortOrder+ parameter.
|
@@ -55,8 +59,10 @@ module Arx
|
|
55
59
|
# @param ids [Array<String>] The IDs of the arXiv papers to restrict the query to.
|
56
60
|
# @param sort_by [Symbol] The sorting criteria for the returned results (see {SORT_BY}).
|
57
61
|
# @param sort_order [Symbol] The sorting order for the returned results (see {SORT_ORDER}).
|
62
|
+
# @param start [Integer] The index of the first returned result.
|
63
|
+
# @param max_results [Integer] The number of results returned by the query
|
58
64
|
# @return [Query] The initialized query object.
|
59
|
-
def initialize(*ids, sort_by: :relevance, sort_order: :descending)
|
65
|
+
def initialize(*ids, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10)
|
60
66
|
@query = String.new
|
61
67
|
|
62
68
|
Validate.sort_by sort_by, permitted: SORT_BY.keys
|
@@ -65,6 +71,9 @@ module Arx
|
|
65
71
|
Validate.sort_order sort_order, permitted: SORT_ORDER.keys
|
66
72
|
@query << "&#{PARAMS[:sort_order]}=#{SORT_ORDER[sort_order]}"
|
67
73
|
|
74
|
+
Validate.paging start, max_results
|
75
|
+
@query << "&#{PARAMS[:start]}=#{start}&#{PARAMS[:max_results]}=#{max_results}"
|
76
|
+
|
68
77
|
ids.flatten!
|
69
78
|
unless ids.empty?
|
70
79
|
ids.map! {|id| Cleaner.extract_id(id, version: true)}
|
@@ -150,6 +159,20 @@ module Arx
|
|
150
159
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
151
160
|
# @return [self]
|
152
161
|
|
162
|
+
# @!method updated_at(*values, connective: :and)
|
163
|
+
# Search for papers by lastUpdatedDate.
|
164
|
+
#
|
165
|
+
# @param values [Array<String>] lastUpdatedDate (string or range) of papers to search for.
|
166
|
+
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
167
|
+
# @return [self]
|
168
|
+
|
169
|
+
# @!method submitted_at(*values, connective: :and)
|
170
|
+
# Search for papers by submittedDate.
|
171
|
+
#
|
172
|
+
# @param values [Array<String>] submittedDate (string or range) of papers to search for.
|
173
|
+
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
174
|
+
# @return [self]
|
175
|
+
|
153
176
|
# @!method all(*values, exact: true, connective: :and)
|
154
177
|
# Search for papers by all fields (see {FIELDS}).
|
155
178
|
#
|
@@ -159,7 +182,8 @@ module Arx
|
|
159
182
|
# @return [self]
|
160
183
|
|
161
184
|
FIELDS.each do |name, field|
|
162
|
-
|
185
|
+
_exact = ![:updated_at, :submitted_at].include?(name)
|
186
|
+
define_method(name) do |*values, exact: _exact, connective: :and|
|
163
187
|
return if values.empty?
|
164
188
|
|
165
189
|
values.flatten!
|
data/lib/arx/query/validate.rb
CHANGED
@@ -29,6 +29,18 @@ module Arx
|
|
29
29
|
raise ArgumentError.new("Expected `sort_order` to be one of #{permitted}, got: #{value}") unless permitted.include? value
|
30
30
|
end
|
31
31
|
|
32
|
+
# Validates the paging fields of the query string: +start+ and +max_results+.
|
33
|
+
#
|
34
|
+
# @param start [Integer] The start value to validate.
|
35
|
+
# @param max_results [Integer] The max_results value to validate.
|
36
|
+
# @raise
|
37
|
+
# [TypeError] If the value of +start+ is not an +Integer+.
|
38
|
+
# [TypeError] If the value of +max_results+ is not an +Integer+.
|
39
|
+
def paging(start, max_results)
|
40
|
+
raise TypeError.new("Expected `start` to be an Integer, got: #{start.class}") unless start.is_a? Integer
|
41
|
+
raise TypeError.new("Expected `max_results` to be an Integer, got: #{max_results.class}") unless max_results.is_a? Integer
|
42
|
+
end
|
43
|
+
|
32
44
|
# Validates a list of arXiv paper identifiers.
|
33
45
|
#
|
34
46
|
# @param ids [Array<String>] The identifiers to validate.
|
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.3.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: 2021-
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|