lib/arx.rb in arx-1.2.1 vs lib/arx.rb in arx-1.3.0
- old
+ new
@@ -1,9 +1,21 @@
# frozen_string_literal: true
require 'cgi'
require 'json'
+
+# Temporary fix for JSON warning in Ruby >= 2.7.0
+# See: https://github.com/flori/json/issues/399#issuecomment-734863279
+if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
+ module JSON
+ module_function
+ def parse(source, opts = {})
+ Parser.new(source, **opts).parse
+ end
+ end
+end
+
require 'nokogiri'
require 'open-uri'
require 'happymapper'
require 'arx/version'
require 'arx/cleaner'
@@ -45,23 +57,25 @@
class << self
# Performs a search query for papers on the arXiv search API.
#
- # @note The +sort_by+ and +sort_order+ arguments are ignored if passing in your own +query+.
+ # @note The +sort_by+, +sort_order+, +start+ and +max_results+ arguments are ignored if passing in your own +query+.
# @param ids [Array<String>] The IDs of the arXiv papers to restrict the query to.
# @param query [Query, NilClass] Predefined search query object.
# @param sort_by [Symbol] The sorting criteria for the returned results (see {Query::SORT_BY}).
# @param sort_order [Symbol] The sorting order for the returned results (see {Query::SORT_ORDER}).
+ # @param start [Integer] The index of the first returned result.
+ # @param max_results [Integer] The number of results returned by the query
# @return [Array<Paper>, Paper] The {Paper}(s) found by the search query.
- def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending)
- query ||= Query.new(*ids, sort_by: sort_by, sort_order: sort_order)
+ def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10)
+ query ||= Query.new(*ids, sort_by: sort_by, sort_order: sort_order, start: start, max_results: max_results)
raise TypeError.new("Expected `query` to be an Arx::Query, got: #{query.class}") unless query.is_a? Query
yield query if block_given?
- document = Nokogiri::XML(URI.open ENDPOINT + query.to_s + '&max_results=10000').remove_namespaces!
+ document = Nokogiri::XML(URI.open ENDPOINT + query.to_s).remove_namespaces!
results = Paper.parse(document, single: ids.size == 1)
if results.is_a? Paper
raise Error::MissingPaper.new(ids.first) if results.title.empty?
elsif results.is_a? Array
@@ -88,9 +102,11 @@
# @see Arx.search
# @param ids [Array<String>] The IDs of the arXiv papers to restrict the query to.
# @param query [Query, NilClass] Predefined search query object.
# @param sort_by [Symbol] The sorting criteria for the returned results (see {Arx::Query::SORT_BY}).
# @param sort_order [Symbol] The sorting order for the returned results (see {Arx::Query::SORT_ORDER}).
+# @param start [Integer] The index of the first returned result.
+# @param max_results [Integer] The number of results returned by the query
# @return [Array<Paper>, Paper] The {Arx::Paper}(s) found by the search query.
-def Arx(*ids, query: nil, sort_by: :relevance, sort_order: :descending, &block)
- Arx.search *ids, query: query, sort_by: sort_by, sort_order: sort_order, &block
+def Arx(*ids, query: nil, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10, &block)
+ Arx.search *ids, query: query, sort_by: sort_by, sort_order: sort_order, start: start, max_results: max_results, &block
end
\ No newline at end of file