living-validator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +9 -1
- data/lib/living-validator.rb +32 -0
- data/lib/living-validator/version.rb +1 -1
- data/living-validator.gemspec +3 -0
- metadata +6 -3
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#LivingValidator gem
|
2
2
|
|
3
|
+
## `gem install living-validator`
|
4
|
+
|
3
5
|
This gem is designed to integrate with the http://validator.nu service. It will work with the public instance or a private instance. The source for the validator is available here: [BitBucket Repo](https://bitbucket.org/validator/build/src).
|
4
6
|
|
5
7
|
The functionality here is pretty basic. You may query the validator, receive a response, and go through the messages it gives you. There are convenience methods for getting only the error messages, getting the total number of error messages, or getting the total number of messages.
|
@@ -14,6 +16,8 @@ The functionality here is pretty basic. You may query the validator, receive a r
|
|
14
16
|
|
15
17
|
##Public Instance
|
16
18
|
|
19
|
+
require 'rubygems' # Only for Ruby 1.8
|
20
|
+
require 'living-validator'
|
17
21
|
result = LivingValidator::Validator.check 'http://github.com'
|
18
22
|
puts "There were #{result.errorCount} errors found!"
|
19
23
|
if result.errorCount > 0
|
@@ -22,6 +26,8 @@ The functionality here is pretty basic. You may query the validator, receive a r
|
|
22
26
|
|
23
27
|
##Private Instance
|
24
28
|
|
29
|
+
require 'rubygems' # Only for Ruby 1.8
|
30
|
+
require 'living-validator'
|
25
31
|
result = LivingValidator::Validator.check 'http://github.com', {:endpoint => 'localhost:8888'}
|
26
32
|
puts "There were #{result.errorCount} errors found!"
|
27
33
|
if result.errorCount > 0
|
@@ -30,6 +36,8 @@ The functionality here is pretty basic. You may query the validator, receive a r
|
|
30
36
|
|
31
37
|
##Lax Content-Type Checking
|
32
38
|
|
39
|
+
require 'rubygems' # Only for Ruby 1.8
|
40
|
+
require 'living-validator'
|
33
41
|
result = LivingValidator::Validator.check 'http://github.com', {:lax_type => true}
|
34
42
|
puts "There were #{result.errorCount} errors found!"
|
35
43
|
if result.errorCount > 0
|
@@ -38,6 +46,6 @@ The functionality here is pretty basic. You may query the validator, receive a r
|
|
38
46
|
|
39
47
|
# License / Copyright
|
40
48
|
|
41
|
-
Copyright (c) 2012
|
49
|
+
Copyright (c) 2012 DynamiX Web Design, LLC (http://www.dynamixwebdesign.com)
|
42
50
|
|
43
51
|
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported. More info in the LICENSE file.
|
data/lib/living-validator.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# @copyright 2012 (c) Dynamix Web Design, LLC
|
2
|
+
# @author Whit Marbut
|
3
|
+
# @license See LICENSE file in gem file or project repository
|
4
|
+
|
1
5
|
require 'rubygems'
|
2
6
|
require 'httparty'
|
3
7
|
require 'json'
|
@@ -18,6 +22,15 @@ module LivingValidator
|
|
18
22
|
# Validator class. Should be accesses statically
|
19
23
|
#
|
20
24
|
class Validator
|
25
|
+
|
26
|
+
# Perform the validation on a given URL against the validator endpoint.
|
27
|
+
# Has two options `:endpoint` and `:lax_type`. The endpoint option configures where the
|
28
|
+
# validator instance is running. It defaults to validator.nu. The lax type option
|
29
|
+
# allows for lax type checking. The default for this is false. Make sure to test the
|
30
|
+
# result of this method for a false falue as this is the failure output.
|
31
|
+
# @param string url The url of the page to validate
|
32
|
+
# @param hash options (optional) The options to use.
|
33
|
+
# @return [LivingValidator::Result,boolean] Returns a result or false for failure.
|
21
34
|
def self.check(url, options = {})
|
22
35
|
# Determine the endpoint url
|
23
36
|
endpoint = options[:endpoint] || ENDPOINT
|
@@ -63,6 +76,12 @@ module LivingValidator
|
|
63
76
|
@url = url
|
64
77
|
end
|
65
78
|
|
79
|
+
# Declares a document valid if no error messages were raised
|
80
|
+
# @return boolean True for a valid document
|
81
|
+
def valid?
|
82
|
+
(self.errorCount) == 0? true : false
|
83
|
+
end
|
84
|
+
|
66
85
|
#
|
67
86
|
# Get the number of errors returned
|
68
87
|
# @return integer the error count
|
@@ -70,6 +89,13 @@ module LivingValidator
|
|
70
89
|
(self.errors()).length
|
71
90
|
end
|
72
91
|
|
92
|
+
#
|
93
|
+
# Get the number of info messages returned
|
94
|
+
# @return integer the info count
|
95
|
+
def infoCount
|
96
|
+
(self.infos()).length
|
97
|
+
end
|
98
|
+
|
73
99
|
#
|
74
100
|
# Get only the error messages
|
75
101
|
# @return array the error messages
|
@@ -77,6 +103,12 @@ module LivingValidator
|
|
77
103
|
@messages.select{|msg| msg['type'] == 'error'}
|
78
104
|
end
|
79
105
|
|
106
|
+
# Get only the info messages
|
107
|
+
# @return array the info messages
|
108
|
+
def infos
|
109
|
+
@messages.select{|msg| msg['type'] == 'info'}
|
110
|
+
end
|
111
|
+
|
80
112
|
#
|
81
113
|
# Get the total messages count
|
82
114
|
# @return integer the messages count
|
data/living-validator.gemspec
CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
|
21
21
|
gem.add_dependency 'httparty', '>= 0.9.0'
|
22
22
|
gem.add_dependency 'json', '1.7.5'
|
23
|
+
|
24
|
+
|
25
|
+
gem.post_install_message = "Thank you for using our gem. Check us out on the web at http://www.dynamixwebdesign.com\n-The DynamiX Team"
|
23
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: living-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -61,7 +61,9 @@ files:
|
|
61
61
|
homepage: https://bitbucket.org/dynamixwd/living-validator
|
62
62
|
licenses:
|
63
63
|
- Creative Commons Attribution-ShareAlike 3.0 Unported
|
64
|
-
post_install_message:
|
64
|
+
post_install_message: ! 'Thank you for using our gem. Check us out on the web at http://www.dynamixwebdesign.com
|
65
|
+
|
66
|
+
-The DynamiX Team'
|
65
67
|
rdoc_options: []
|
66
68
|
require_paths:
|
67
69
|
- lib
|
@@ -84,3 +86,4 @@ signing_key:
|
|
84
86
|
specification_version: 3
|
85
87
|
summary: A simple suite for querying the validator.nu service (or your own instance).
|
86
88
|
test_files: []
|
89
|
+
has_rdoc:
|