Class: W3CValidators::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/w3c_validators/message.rb

Constant Summary collapse

MESSAGE_TYPES =
[:warning, :error]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, message_type, options = {}) ⇒ Message

Due to the responses received from the W3C’s validators, different data are available for different validation types.

Feed validation

  • line

  • col

  • message (originally text)

  • message_count

  • element

  • parent

  • value

See validator.w3.org/feed/docs/soap.html#soap12message for full explanations.

Markup validation

  • line

  • col

  • message

  • message_id

  • explanation

  • source

See validator.w3.org/docs/api.html#soap12message for full explanations.

CSS validation (jigsaw.w3.org/css-validator/api.html#soap12message)

  • level

  • line

  • message

  • context

  • skippedstring

See jigsaw.w3.org/css-validator/api.html#soap12message for full explanations.



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
# File 'lib/w3c_validators/message.rb', line 37

def initialize(uri, message_type, options = {})
  @type = message_type
  @uri = uri

  # All validators
  @line = options[:line]
  @col = options[:col]
  
  # MarkupValidator
  @source = options[:source]
  @explanation = options[:explanation]
  @message = options[:message]
  @message_id = options[:messageid]

  # FeedValidator
  @message = options[:text] unless @message
  @message_count = options[:message_count]
  @element = options[:element]
  @parent = options[:parent]
  @value = options[:value]

  # CSSValidator
  @level          = options[:level]
  @context        = options[:context].strip       if options[:context]
  @skippedstring  = options[:skippedstring].strip if options[:skippedstring]
end

Instance Attribute Details

#colObject

Returns the value of attribute col.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def col
  @col
end

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def context
  @context
end

#elementObject

Returns the value of attribute element.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def element
  @element
end

#explanationObject

Returns the value of attribute explanation.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def explanation
  @explanation
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def line
  @line
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def message
  @message
end

#message_countObject

Returns the value of attribute message_count.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def message_count
  @message_count
end

#message_idObject

Returns the value of attribute message_id.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def message_id
  @message_id
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def parent
  @parent
end

#skippedstringObject

Returns the value of attribute skippedstring.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def skippedstring
  @skippedstring
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def source
  @source
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/w3c_validators/message.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/w3c_validators/message.rb', line 4

def value
  @value
end

Instance Method Details

#is_error?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/w3c_validators/message.rb', line 68

def is_error?
  @type == :error
end

#is_warning?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/w3c_validators/message.rb', line 64

def is_warning?
  @type == :warning
end

#to_sObject

Return the message as a string.



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/w3c_validators/message.rb', line 73

def to_s
  str = @type.to_s.upcase
  if @uri and not @uri.empty?
    str << "; URI: #{@uri}"
  end
  str << "; line #{@line}"
  if @message and not @message.empty?
    str << ": #{@message}"
  end
  return str
end