Class: BBCStandards::Validator
- Inherits:
-
Object
- Object
- BBCStandards::Validator
- Includes:
- Spec::Matchers
- Defined in:
- lib/bbc_standards/validator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(xml) ⇒ Validator
constructor
A new instance of Validator.
- #inspect ⇒ Object
- #valid? ⇒ Boolean
Methods included from Spec::Matchers
Constructor Details
#initialize(xml) ⇒ Validator
Returns a new instance of Validator.
7 8 9 10 11 12 13 14 15 |
# File 'lib/bbc_standards/validator.rb', line 7 def initialize(xml) @xml = xml # TODO: remove this once Barlesque sorts out the BBC Search form @xml.sub!('<form method="get" action="http://search.bbc.co.uk/search" accept-charset="utf-8"> <fieldset> <input', '<form method="get" action="http://search.bbc.co.uk/search" accept-charset="utf-8"><fieldset><legend>foo</legend><input') @doc = Nokogiri::HTML(xml) @errors = [] validate end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/bbc_standards/validator.rb', line 5 def errors @errors end |
Instance Method Details
#inspect ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bbc_standards/validator.rb', line 21 def inspect lines = @xml.split("\n") strings = [] errors.each do |error| if error.line start = error.line - [2, error.line].min error_line = error.line == 0 ? 1 : error.line strings << "Error on line: #{error_line}:" strings << error..gsub(/\{[^\}]*\}/, '') Range.new(start, error.line + 2).each { |number| strings << "#{number + 1}: #{lines[number]}" } strings << "" else strings << error. end end strings.join("\n") end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/bbc_standards/validator.rb', line 17 def valid? @errors.empty? end |