Class: W3CValidatorToRally::W3CValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/w3c-validator-to-rally.rb

Instance Method Summary collapse

Instance Method Details

#defineURI(uri) ⇒ Object



15
16
17
# File 'lib/w3c-validator-to-rally.rb', line 15

def defineURI(uri)
	$URI = uri
end

#getURIObject



23
24
25
# File 'lib/w3c-validator-to-rally.rb', line 23

def getURI
	return $URI
end

#showURIObject



19
20
21
# File 'lib/w3c-validator-to-rally.rb', line 19

def showURI
	puts $URI
end

#startValidation(agentMechanize = "Windows Mozilla") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/w3c-validator-to-rally.rb', line 27

def startValidation(agentMechanize="Windows Mozilla")
	mechanize = Mechanize.new { |agent| agent.user_agent_alias = agentMechanize }
	mechanize.get("http://validator.w3.org")
	forms = mechanize.page.forms.first
	forms['uri'] = $URI
	forms.submit

	results = mechanize.page.search(".msg_err")

	puts "#{results.length} error(s) found!\n"

	errors = Array.new results.length

	index = 0

	testFirstError = results.first.elements[1].text.gsub("\n","").gsub("\t","").gsub("         ","")

	if ((results.length == 1) and (testFirstError.start_with?("        Sorry")))
		begin
			 encodeError = results.first.elements[2].text.gsub("\n","").gsub("\t","").gsub("         ","")
			 errors[index] = encodeError, "Encode error found"
		end

	else
		begin
			results.each do |mountDefect|

				teste = mountDefect.elements[1].to_s
				teste = teste.gsub(/<\/?[^>]*>/, "").gsub("\n","").gsub("        ","")

				name = mountDefect.elements[2].to_s
				name = name.gsub('<span class="msg">',"").gsub('</span>',"")
				name = name.slice(0,255)

				completeName = teste + " : " + name

				#decode = HTMLEntities.new
				description = mountDefect.elements[3].to_s
				description = description.gsub(/<\/?[^>]*>/, "").gsub("\t","")
				#description = decode.decode(description)

				errors[index] = completeName,description
				index = index + 1
			end
		end
	end

	return errors

end