class Copyscape::Response
Attributes
Public Class Methods
# File lib/copyscape/response.rb, line 9 def initialize(buffer) @raw_response = buffer @document = Nokogiri(buffer) end
Public Instance Methods
Percentage of source words matched Present: if succeeded and c>=3 and o is not cpsearch
# File lib/copyscape/response.rb, line 54 def allpercentmatched (field('allpercentmatched') || 0).to_i end
Full extract of source text matched Present: if succeeded and c>=3 and o is not cpsearch
# File lib/copyscape/response.rb, line 61 def alltextmatched field('alltextmatched') end
URL for viewing found results Present: if succeeded and o is csearch The <allviewurl> value can be used to display the list of results in an iframe or window. If used, the contents of this page must be displayed in full, without modification.
# File lib/copyscape/response.rb, line 70 def allviewurl field('allviewurl') end
Number of source words matched Present: if succeeded and c>=3 and o is not cpsearch
# File lib/copyscape/response.rb, line 47 def allwordsmatched (field('allwordsmatched') || 0).to_i end
Returns the number of duplicates
# File lib/copyscape/response.rb, line 28 def count (field('count') || 0).to_i end
Returns true if there are one or more duplicates
# File lib/copyscape/response.rb, line 75 def duplicate? count > 0 end
Returns an array of all the results in the form of a hash:
# File lib/copyscape/response.rb, line 80 def duplicates @duplicates ||= [].tap do |r| @document.search('result').collect do |result| r << result_to_hash(result) end end end
Reason for API request failure Present: if request failed
# File lib/copyscape/response.rb, line 40 def error field('error') end
Returns true if the response was an error
# File lib/copyscape/response.rb, line 33 def error? !!error end
URL searched Presert: if a URL search The <query> value may differ from the original URL you supplied if there was a frameset or redirection.
# File lib/copyscape/response.rb, line 18 def query field('query') end
Number of words checked
# File lib/copyscape/response.rb, line 23 def query_words (field('querywords') || 0).to_i end
Private Instance Methods
# File lib/copyscape/response.rb, line 98 def field(name) node = @document.search(name).first node.text if node end
Given a result xml element, return a hash of the values we're interested in.
# File lib/copyscape/response.rb, line 91 def result_to_hash(result) result.children.inject({}) do |hash, node| hash[node.name] = (node.text =~ /^\d+$/ ? node.text.to_i : node.text) hash end end