1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
require 'cucumber/core/ast/describes_itself'
require 'cucumber/core/ast/location'
require 'cucumber/core/ast/names'
module Cucumber
module Core
module Ast
class ExamplesTable
include Names
include HasLocation
include DescribesItself
def initialize(location, comments, tags, keyword, name, description, header, example_rows)
@location = location
@comments = comments
@tags = tags
@keyword = keyword
@name = name
@description = description
@header = header
@example_rows = example_rows
end
attr_reader :location, :tags, :keyword, :comments,
:header, :example_rows
private
def description_for_visitors
:examples_table
end
def children
@example_rows
end
class Header
include HasLocation
attr_reader :comments
def initialize(cells, location, comments)
@cells = cells
@location = location
@comments = comments
end
def values
@cells
end
def build_row(row_cells, number, location, language, comments)
Row.new(Hash[@cells.zip(row_cells)], number, location, language, comments)
end
def inspect
"#<#{self.class} #{values} (#{location})>"
end
end
class Row
include DescribesItself
include HasLocation
attr_reader :number, :language, :comments
def initialize(data, number, location, language, comments)
raise ArgumentError, data.to_s unless data.is_a?(Hash)
@data = data
@number = number
@location = location
@language = language
@comments = comments
end
def ==(other)
return false unless other.class == self.class
other.number == number &&
other.location == location &&
other.data == data
end
def values
@data.values
end
def expand(string)
result = string.dup
@data.each do |key, value|
result.gsub!("<#{key}>", value.to_s)
end
result
end
def inspect
"#<#{self.class}: #{@data.inspect} (#{location})>"
end
protected
attr_reader :data
private
def description_for_visitors
:examples_table_row
end
end
end
class Examples < ExamplesTable; end
end
end
end
|