Class: HTML5::TestSupport::TestData

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/feed_tools/vendor/html5/tests/preamble.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, sections) ⇒ TestData

Returns a new instance of TestData.



40
41
42
43
# File 'lib/feed_tools/vendor/html5/tests/preamble.rb', line 40

def initialize(filename, sections)
  @f = open(filename)
  @sections = sections
end

Instance Method Details

#each {|normaliseOutput(data)| ... } ⇒ Object

Yields:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/feed_tools/vendor/html5/tests/preamble.rb', line 45

def each
  data = {}
  key = nil
  @f.each_line do |line|
    if line[0] == ?# and @sections.include?(line[1..-2])
      heading = line[1..-2]
      if data.any? and heading == @sections[0]
        data[key].chomp!  #Remove trailing newline
        yield normaliseOutput(data)
        data = {}
      end
      key = heading
      data[key]=""
    elsif key
      data[key] += line
    end
  end
  yield normaliseOutput(data) if data
end

#normaliseOutput(data) ⇒ Object



65
66
67
68
69
# File 'lib/feed_tools/vendor/html5/tests/preamble.rb', line 65

def normaliseOutput(data)
  #Remove trailing newlines
  data.keys.each { |key| data[key].chomp! }
  @sections.map {|heading| data[heading]}
end