class Copyscape::Response

Attributes

raw_response[R]

Public Class Methods

new(buffer) click to toggle source
# File lib/copyscape/response.rb, line 9
def initialize(buffer)
  @raw_response = buffer
  @document = Nokogiri(buffer)
end

Public Instance Methods

allpercentmatched() click to toggle source

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
alltextmatched() click to toggle source

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
allviewurl() click to toggle source

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
allwordsmatched() click to toggle source

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
count() click to toggle source

Returns the number of duplicates

# File lib/copyscape/response.rb, line 28
def count
  (field('count') || 0).to_i
end
duplicate?() click to toggle source

Returns true if there are one or more duplicates

# File lib/copyscape/response.rb, line 75
def duplicate?
  count > 0
end
duplicates() click to toggle source

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
error() click to toggle source

Reason for API request failure Present: if request failed

# File lib/copyscape/response.rb, line 40
def error
  field('error')
end
error?() click to toggle source

Returns true if the response was an error

# File lib/copyscape/response.rb, line 33
def error?
  !!error
end
query() click to toggle source

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
query_words() click to toggle source

Number of words checked

# File lib/copyscape/response.rb, line 23
def query_words
  (field('querywords') || 0).to_i
end

Private Instance Methods

field(name) click to toggle source
# File lib/copyscape/response.rb, line 98
def field(name)
  node = @document.search(name).first
  node.text if node
end
result_to_hash(result) click to toggle source

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