Class: Cucumber::Ast::Table
Overview
Holds the data of a table parsed from a feature file:
| a | b |
| c | d |
This gets parsed into a Table holding the values [['a', 'b'], ['c', 'd']]
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #accept(visitor, status) ⇒ Object
-
#arguments_replaced(arguments) ⇒ Object
:nodoc:.
- #at_lines?(lines) ⇒ Boolean
-
#hashes ⇒ Object
Converts this table into an Array of Hash where the keys of each Hash are the headers in the table.
-
#index(cells) ⇒ Object
:nodoc:.
-
#initialize(raw) ⇒ Table
constructor
A new instance of Table.
-
#raw ⇒ Object
Gets the raw data of this table.
-
#to_hash(cells) ⇒ Object
:nodoc:.
-
#to_sexp ⇒ Object
For testing only.
Constructor Details
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
11 12 13 |
# File 'lib/cucumber/ast/table.rb', line 11 def file @file end |
Instance Method Details
#accept(visitor, status) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/cucumber/ast/table.rb', line 25 def accept(visitor, status) rows.each do |row| visitor.visit_table_row(row, status) end nil end |
#arguments_replaced(arguments) ⇒ Object
:nodoc:
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cucumber/ast/table.rb', line 86 def arguments_replaced(arguments) #:nodoc: raw_with_replaced_args = raw.map do |row| row.map do |cell| cell_with_replaced_args = cell arguments.each do |name, value| cell_with_replaced_args = cell_with_replaced_args.gsub(name, value) end cell_with_replaced_args end end Table.new(raw_with_replaced_args) end |
#at_lines?(lines) ⇒ Boolean
21 22 23 |
# File 'lib/cucumber/ast/table.rb', line 21 def at_lines?(lines) rows.detect { |row| row.at_lines?(lines) } end |
#hashes ⇒ Object
Converts this table into an Array of Hash where the keys of each Hash are the headers in the table. For example, a Table built from the following plain text:
| a | b | sum |
| 2 | 3 | 5 |
| 7 | 9 | 16 |
Gets converted into the following:
[{'a' => '2', 'b' => '3', 'sum' => '5'}, {'a' => '7', 'b' => '9', 'sum' => '16'}]
44 45 46 47 48 |
# File 'lib/cucumber/ast/table.rb', line 44 def hashes @hashes ||= rows[1..-1].map do |row| row.to_hash end end |
#index(cells) ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/cucumber/ast/table.rb', line 82 def index(cells) #:nodoc: rows.index(cells) end |
#raw ⇒ Object
Gets the raw data of this table. For example, a Table built from the following plain text:
| a | b |
| c | d |
Get converted into the following:
[['a', 'b], ['c', 'd']]
60 61 62 |
# File 'lib/cucumber/ast/table.rb', line 60 def raw @raw end |
#to_hash(cells) ⇒ Object
:nodoc:
74 75 76 77 78 79 80 |
# File 'lib/cucumber/ast/table.rb', line 74 def to_hash(cells) #:nodoc: hash = {} @raw[0].each_with_index do |key, n| hash[key] = cells.value(n) end hash end |
#to_sexp ⇒ Object
For testing only
70 71 72 |
# File 'lib/cucumber/ast/table.rb', line 70 def to_sexp #:nodoc: [:table, *rows.map{|row| row.to_sexp}] end |