Class: Plagiarism::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/plagiarism/search.rb

Direct Known Subclasses

TextSearch, URLSearch

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#requestObject

Returns the value of attribute request.



4
5
6
# File 'lib/plagiarism/search.rb', line 4

def request
  @request
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/plagiarism/search.rb', line 4

def response
  @response
end

Instance Method Details

#countObject

Return the number of results found



9
10
11
# File 'lib/plagiarism/search.rb', line 9

def count
  @response.success? ? @response.doc.css("count").text.to_i : nil
end

#error?Boolean

Return true if an error occurred

Returns:

  • (Boolean)


22
23
24
# File 'lib/plagiarism/search.rb', line 22

def error?
  @response && @response.error? ? true : false
end

#percentage_matchedObject

Return the percentage of words matched from the source



54
55
56
57
58
59
60
# 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?Boolean

Return true if any results were found

Returns:

  • (Boolean)


16
17
18
# File 'lib/plagiarism/search.rb', line 16

def results?
  count && count > 0 ? true : false
end

#results_urlObject

Return the URL for viewing results



65
66
67
# File 'lib/plagiarism/search.rb', line 65

def results_url
  @response.doc.css("allviewurl").text if results?
end

#success?Boolean

Return true if the search request was successful

Returns:

  • (Boolean)


29
30
31
# File 'lib/plagiarism/search.rb', line 29

def success?
  @response && @response.success? ? true : false
end

#wordsObject

Return the number of words checked



36
37
38
# File 'lib/plagiarism/search.rb', line 36

def words
  @response.success? ? @response.doc.css("querywords").text.to_i : nil
end

#words_matchedObject

Return the number of words matched from the source



43
44
45
46
47
48
49
# 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