class Plagiarism::Search
Attributes
request[RW]
response[RW]
Public Instance Methods
count()
click to toggle source
Return the number of results found
# File lib/plagiarism/search.rb, line 9 def count @response.success? ? @response.doc.css("count").text.to_i : nil end
error?()
click to toggle source
Return true if an error occurred
# File lib/plagiarism/search.rb, line 22 def error? @response && @response.error? ? true : false end
percentage_matched()
click to toggle source
Return the percentage of words matched from the source
# File lib/plagiarism/search.rb, line 54 def percentage_matched if @response.success? && percentage = @response.doc.css("allpercentmatched").text percentage != "" ? percentage.to_i : nil else nil end end
results?()
click to toggle source
Return true if any results were found
# File lib/plagiarism/search.rb, line 16 def results? count && count > 0 ? true : false end
results_url()
click to toggle source
Return the URL for viewing results
# File lib/plagiarism/search.rb, line 65 def results_url @response.doc.css("allviewurl").text if results? end
success?()
click to toggle source
Return true if the search request was successful
# File lib/plagiarism/search.rb, line 29 def success? @response && @response.success? ? true : false end
words()
click to toggle source
Return the number of words checked
# File lib/plagiarism/search.rb, line 36 def words @response.success? ? @response.doc.css("querywords").text.to_i : nil end
words_matched()
click to toggle source
Return the number of words matched from the source
# File lib/plagiarism/search.rb, line 43 def words_matched if @response.success? && words = @response.doc.css("allwordsmatched").text words != "" ? words.to_i : nil else nil end end
Protected Instance Methods
operation_for_scope(scope)
click to toggle source
Map search scope to an api operation
# File lib/plagiarism/search.rb, line 85 def operation_for_scope(scope) if scope && scope.to_sym == :full "cpsearch" elsif scope && scope.to_sym == :private "psearch" else "csearch" end end
search_params(options)
click to toggle source
# File lib/plagiarism/search.rb, line 73 def search_params(options) params = { o: operation_for_scope(options[:scope]), c: options[:full_comparisons] || 0 } params.merge!(e: options[:encoding]) if options[:encoding] && self.class == TextSearch params end