Class: LivingValidator::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/living-validator.rb

Overview

Validator results class with convenience functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, messages) ⇒ Result

Construct a new result set from the url and messages

Parameters:

  • string

    url the url of the site checked

  • array

    messages the array of messages from the validator



74
75
76
77
# File 'lib/living-validator.rb', line 74

def initialize(url, messages)
	@messages = messages
	@url = url
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



68
69
70
# File 'lib/living-validator.rb', line 68

def messages
  @messages
end

#urlObject (readonly)

Returns the value of attribute url.



68
69
70
# File 'lib/living-validator.rb', line 68

def url
  @url
end

Instance Method Details

#errorCountObject

Get the number of errors returned

Returns:

  • integer the error count



88
89
90
# File 'lib/living-validator.rb', line 88

def errorCount
	(self.errors()).length
end

#errorsObject

Get only the error messages

Returns:

  • array the error messages



102
103
104
# File 'lib/living-validator.rb', line 102

def errors
	@messages.select{|msg| msg['type'] == 'error'}
end

#infoCountObject

Get the number of info messages returned

Returns:

  • integer the info count



95
96
97
# File 'lib/living-validator.rb', line 95

def infoCount
	(self.infos()).length
end

#infosObject

Get only the info messages

Returns:

  • array the info messages



108
109
110
# File 'lib/living-validator.rb', line 108

def infos
	@messages.select{|msg| msg['type'] == 'info'}
end

#messageCountObject

Get the total messages count

Returns:

  • integer the messages count



115
116
117
# File 'lib/living-validator.rb', line 115

def messageCount
	@messages.length
end

#valid?Boolean

Declares a document valid if no error messages were raised

Returns:

  • (Boolean)

    boolean True for a valid document



81
82
83
# File 'lib/living-validator.rb', line 81

def valid?
	(self.errorCount) == 0? true : false
end