arx 0.3.2 → 1.2.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.
@@ -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
@@ -22,14 +22,8 @@ module Arx
22
22
  and_not: 'ANDNOT'
23
23
  }
24
24
 
25
- # Logical connective method names.
26
- CONNECTIVE_METHODS = {
27
- '&': :and,
28
- '!': :and_not,
29
- '|': :or
30
- }
31
-
32
25
  # Supported fields for the search queries made to the arXiv search API.
26
+ #
33
27
  # @see https://arxiv.org/help/prep arXiv metadata fields
34
28
  # @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual (query details)
35
29
  FIELDS = {
@@ -73,35 +67,38 @@ module Arx
73
67
 
74
68
  ids.flatten!
75
69
  unless ids.empty?
76
- ids.map! {|id| extract_id id}
77
- Validate.ids ids
70
+ ids.map! {|id| Cleaner.extract_id(id, version: true)}
78
71
  @query << "&#{PARAMS[:id_list]}=#{ids * ','}"
79
72
  end
80
73
 
81
74
  yield self if block_given?
82
75
  end
83
76
 
84
- # @!method &
77
+ # @!method and
85
78
  # Logical conjunction (+AND+) of subqueries.
79
+ #
86
80
  # @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
87
81
  # @return [self]
88
82
 
89
- # @!method !
83
+ # @!method and_not
90
84
  # Logical negated conjunction (+ANDNOT+) of subqueries.
85
+ #
91
86
  # @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
92
87
  # @return [self]
93
88
 
94
- # @!method |
89
+ # @!method or
95
90
  # Logical disjunction (+OR+) of subqueries.
91
+ #
96
92
  # @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
97
93
  # @return [self]
98
94
 
99
- CONNECTIVE_METHODS.each do |symbol, connective|
100
- define_method(symbol) { add_connective connective }
95
+ CONNECTIVES.keys.each do |connective|
96
+ define_method(connective) { add_connective connective }
101
97
  end
102
98
 
103
99
  # @!method title(*values, exact: true, connective: :and)
104
100
  # Search for papers by {https://arxiv.org/help/prep#title title}.
101
+ #
105
102
  # @param values [Array<String>] Title(s) of papers to search for.
106
103
  # @param exact [Boolean] Whether to search for an exact match of the title(s).
107
104
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -109,6 +106,7 @@ module Arx
109
106
 
110
107
  # @!method author(*values, exact: true, connective: :and)
111
108
  # Search for papers by {https://arxiv.org/help/prep#author author}.
109
+ #
112
110
  # @param values [Array<String>] Author(s) of papers to search for.
113
111
  # @param exact [Boolean] Whether to search for an exact match of the author's name(s).
114
112
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -116,6 +114,7 @@ module Arx
116
114
 
117
115
  # @!method abstract(*values, exact: true, connective: :and)
118
116
  # Search for papers by {https://arxiv.org/help/prep#abstract abstract}.
117
+ #
119
118
  # @param values [Array<String>] Abstract(s) of papers to search for.
120
119
  # @param exact [Boolean] Whether to search for an exact match of the abstract(s).
121
120
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -123,6 +122,7 @@ module Arx
123
122
 
124
123
  # @!method comment(*values, exact: true, connective: :and)
125
124
  # Search for papers by {https://arxiv.org/help/prep#comments comment}.
125
+ #
126
126
  # @param values [Array<String>] Comment(s) of papers to search for.
127
127
  # @param exact [Boolean] Whether to search for an exact match of the comment(s).
128
128
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -130,6 +130,7 @@ module Arx
130
130
 
131
131
  # @!method journal(*values, exact: true, connective: :and)
132
132
  # Search for papers by {https://arxiv.org/help/prep#journal journal reference}.
133
+ #
133
134
  # @param values [Array<String>] Journal reference(s) of papers to search for.
134
135
  # @param exact [Boolean] Whether to search for an exact match of the journal refernece(s).
135
136
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -137,18 +138,21 @@ module Arx
137
138
 
138
139
  # @!method category(*values, connective: :and)
139
140
  # Search for papers by {https://arxiv.org/help/prep#category category}.
141
+ #
140
142
  # @param values [Array<String>] Category(s) of papers to search for.
141
143
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
142
144
  # @return [self]
143
145
 
144
146
  # @!method report(*values, connective: :and)
145
147
  # Search for papers by {https://arxiv.org/help/prep#report report number}.
148
+ #
146
149
  # @param values [Array<String>] Report number(s) of papers to search for.
147
150
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
148
151
  # @return [self]
149
152
 
150
153
  # @!method all(*values, exact: true, connective: :and)
151
154
  # Search for papers by all fields (see {FIELDS}).
155
+ #
152
156
  # @param values [Array<String>] Field value(s) of papers to search for.
153
157
  # @param exact [Boolean] Whether to search for an exact match of the comment(s).
154
158
  # @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
@@ -181,6 +185,20 @@ module Arx
181
185
  end
182
186
  end
183
187
 
188
+ # Creates a nested subquery (grouped statements with parentheses).
189
+ #
190
+ # @return [self]
191
+ def group
192
+ add_connective :and unless end_with_connective?
193
+ @query << (search_query? ? '+' : "&#{PARAMS[:search_query]}=")
194
+
195
+ @query << CGI.escape('(')
196
+ yield
197
+ @query << CGI.escape(')')
198
+
199
+ self
200
+ end
201
+
184
202
  # Returns the query string.
185
203
  #
186
204
  # @return [String]
@@ -196,8 +214,9 @@ module Arx
196
214
  # @param connective [Symbol] The symbol of the logical connective to add.
197
215
  # @return [self]
198
216
  def add_connective(connective)
199
- return unless search_query?
200
- @query << "+#{CONNECTIVES[connective]}" unless ends_with_connective?
217
+ if search_query?
218
+ @query << "+#{CONNECTIVES[connective]}" unless end_with_connective? || start_of_group?
219
+ end
201
220
  self
202
221
  end
203
222
 
@@ -205,13 +224,10 @@ module Arx
205
224
  #
206
225
  # @param subquery [String] The subquery to add.
207
226
  def add_subquery(subquery)
227
+ add_connective :and unless end_with_connective?
228
+
208
229
  if search_query?
209
- if ends_with_connective?
210
- @query << "+#{subquery}"
211
- else
212
- add_connective :and
213
- @query << "+#{subquery}"
214
- end
230
+ @query << (start_of_group? ? "#{subquery}" : "+#{subquery}")
215
231
  else
216
232
  @query << "&#{PARAMS[:search_query]}=#{subquery}"
217
233
  end
@@ -229,10 +245,17 @@ module Arx
229
245
  #
230
246
  # @see CONNECTIVES
231
247
  # @return [Boolean]
232
- def ends_with_connective?
248
+ def end_with_connective?
233
249
  CONNECTIVES.values.any? &@query.method(:end_with?)
234
250
  end
235
251
 
252
+ # Whether the query string ends in a start-of-group character '('.
253
+ #
254
+ # @return [Boolean]
255
+ def start_of_group?
256
+ @query.end_with? CGI.escape('(')
257
+ end
258
+
236
259
  # Parenthesizes a string with CGI-escaped parentheses.
237
260
  #
238
261
  # @param string [String] The string to parenthesize.
@@ -248,18 +271,5 @@ module Arx
248
271
  def enquote(string)
249
272
  CGI.escape("\"") + string + CGI.escape("\"")
250
273
  end
251
-
252
- # Attempt to extract an ID from an arXiv URL.
253
- #
254
- # @param url [String] The URL to extract the ID from.
255
- # @return [String] The extracted ID if successful, otherwise the original string.
256
- def extract_id(url)
257
- prefix = %r"^(https?\:\/\/)?(www.)?arxiv\.org\/abs\/"
258
- if %r"#{prefix}.*$".match? url
259
- url.sub(prefix, '').sub(%r"\/$", '')
260
- else
261
- url
262
- end
263
- end
264
274
  end
265
275
  end
@@ -1,6 +1,7 @@
1
1
  module Arx
2
2
 
3
3
  # Validations for arXiv search query fields and identifier schemes.
4
+ #
4
5
  # @private
5
6
  module Validate
6
7
  class << self
@@ -94,7 +95,9 @@ module Arx
94
95
  # @see NEW_IDENTIFIER_FORMAT
95
96
  # @see OLD_IDENTIFIER_FORMAT
96
97
  def id?(id)
97
- NEW_IDENTIFIER_FORMAT.match?(id) || OLD_IDENTIFIER_FORMAT.match?(id)
98
+ return true if NEW_IDENTIFIER_FORMAT.match? id
99
+ return true if OLD_IDENTIFIER_FORMAT.match?(id) && Arx::CATEGORIES.keys.include?(id.split('/').first)
100
+ false
98
101
  end
99
102
  end
100
103
  end
@@ -4,9 +4,9 @@ module Arx
4
4
 
5
5
  # The current version of Arx.
6
6
  VERSION = {
7
- major: 0,
8
- minor: 3,
9
- patch: 2,
7
+ major: 1,
8
+ minor: 2,
9
+ patch: 1,
10
10
  meta: nil,
11
11
  }.compact.values.join('.').freeze
12
12
  end
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: 0.3.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Onuonga
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-30 00:00:00.000000000 Z
11
+ date: 2021-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -42,44 +42,44 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '12.3'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '12.3'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.20'
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.20'
82
+ version: 0.20.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,9 +94,43 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.7'
97
- description:
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.8.23
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
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
131
+ description:
98
132
  email:
99
- - ed@mail.eonu.net
133
+ - ed@eonu.net
100
134
  executables: []
101
135
  extensions: []
102
136
  extra_rdoc_files: []
@@ -128,13 +162,13 @@ metadata:
128
162
  documentation_uri: https://www.rubydoc.info/github/eonu/arx/master/toplevel
129
163
  bug_tracker_uri: https://github.com/eonu/arx/issues
130
164
  changelog_uri: https://github.com/eonu/arx/blob/master/CHANGELOG.md
131
- post_install_message:
165
+ post_install_message:
132
166
  rdoc_options: []
133
167
  require_paths:
134
168
  - lib
135
169
  required_ruby_version: !ruby/object:Gem::Requirement
136
170
  requirements:
137
- - - "~>"
171
+ - - ">="
138
172
  - !ruby/object:Gem::Version
139
173
  version: '2.5'
140
174
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -143,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
177
  - !ruby/object:Gem::Version
144
178
  version: '0'
145
179
  requirements: []
146
- rubygems_version: 3.0.3
147
- signing_key:
180
+ rubygems_version: 3.1.2
181
+ signing_key:
148
182
  specification_version: 4
149
183
  summary: A Ruby interface for querying academic papers on the arXiv search API.
150
184
  test_files: []