cuke_modeler 3.27.0 → 3.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +579 -572
  3. data/LICENSE.txt +22 -22
  4. data/README.md +135 -135
  5. data/cuke_modeler.gemspec +59 -59
  6. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +13 -13
  7. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +13 -13
  8. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +13 -13
  9. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +13 -13
  10. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +13 -13
  11. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +13 -13
  12. data/lib/cuke_modeler/adapters/gherkin_16_adapter.rb +13 -13
  13. data/lib/cuke_modeler/adapters/gherkin_17_adapter.rb +13 -13
  14. data/lib/cuke_modeler/adapters/gherkin_18_adapter.rb +27 -27
  15. data/lib/cuke_modeler/adapters/gherkin_19_adapter.rb +64 -64
  16. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +359 -359
  17. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +13 -13
  18. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +13 -13
  19. data/lib/cuke_modeler/adapters/gherkin_23_adapter.rb +13 -13
  20. data/lib/cuke_modeler/adapters/gherkin_24_adapter.rb +13 -13
  21. data/lib/cuke_modeler/adapters/gherkin_25_adapter.rb +13 -13
  22. data/lib/cuke_modeler/adapters/gherkin_26_adapter.rb +13 -13
  23. data/lib/cuke_modeler/adapters/gherkin_27_adapter.rb +13 -13
  24. data/lib/cuke_modeler/adapters/gherkin_28_adapter.rb +13 -13
  25. data/lib/cuke_modeler/adapters/gherkin_29_adapter.rb +13 -13
  26. data/lib/cuke_modeler/adapters/gherkin_30_adapter.rb +13 -13
  27. data/lib/cuke_modeler/adapters/gherkin_31_adapter.rb +13 -13
  28. data/lib/cuke_modeler/adapters/gherkin_32_adapter.rb +13 -13
  29. data/lib/cuke_modeler/adapters/gherkin_33_adapter.rb +13 -13
  30. data/lib/cuke_modeler/adapters/gherkin_34_adapter.rb +13 -13
  31. data/lib/cuke_modeler/adapters/gherkin_35_adapter.rb +13 -13
  32. data/lib/cuke_modeler/adapters/gherkin_36_adapter.rb +13 -13
  33. data/lib/cuke_modeler/adapters/gherkin_37_adapter.rb +13 -13
  34. data/lib/cuke_modeler/adapters/gherkin_38_adapter.rb +13 -0
  35. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +375 -375
  36. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +17 -17
  37. data/lib/cuke_modeler/containing.rb +105 -105
  38. data/lib/cuke_modeler/described.rb +71 -71
  39. data/lib/cuke_modeler/models/background.rb +122 -122
  40. data/lib/cuke_modeler/models/cell.rb +88 -88
  41. data/lib/cuke_modeler/models/comment.rb +82 -82
  42. data/lib/cuke_modeler/models/directory.rb +143 -143
  43. data/lib/cuke_modeler/models/doc_string.rb +104 -104
  44. data/lib/cuke_modeler/models/example.rb +274 -274
  45. data/lib/cuke_modeler/models/feature.rb +200 -200
  46. data/lib/cuke_modeler/models/feature_file.rb +116 -116
  47. data/lib/cuke_modeler/models/model.rb +87 -87
  48. data/lib/cuke_modeler/models/outline.rb +145 -145
  49. data/lib/cuke_modeler/models/row.rb +104 -104
  50. data/lib/cuke_modeler/models/rule.rb +162 -162
  51. data/lib/cuke_modeler/models/scenario.rb +128 -128
  52. data/lib/cuke_modeler/models/step.rb +178 -178
  53. data/lib/cuke_modeler/models/table.rb +117 -117
  54. data/lib/cuke_modeler/models/tag.rb +75 -75
  55. data/lib/cuke_modeler/named.rb +26 -26
  56. data/lib/cuke_modeler/nested.rb +61 -61
  57. data/lib/cuke_modeler/parsed.rb +24 -24
  58. data/lib/cuke_modeler/parsing.rb +208 -208
  59. data/lib/cuke_modeler/sourceable.rb +29 -29
  60. data/lib/cuke_modeler/stepped.rb +34 -34
  61. data/lib/cuke_modeler/taggable.rb +57 -57
  62. data/lib/cuke_modeler/version.rb +4 -4
  63. data/lib/cuke_modeler.rb +32 -32
  64. data/testing/cucumber/features/analysis/step_comparison.feature +25 -25
  65. data/testing/cucumber/features/analysis/test_comparison.feature +35 -35
  66. data/testing/cucumber/features/modeling/background_modeling.feature +105 -105
  67. data/testing/cucumber/features/modeling/background_output.feature +60 -60
  68. data/testing/cucumber/features/modeling/cell_modeling.feature +68 -68
  69. data/testing/cucumber/features/modeling/cell_output.feature +36 -36
  70. data/testing/cucumber/features/modeling/comment_modeling.feature +62 -62
  71. data/testing/cucumber/features/modeling/comment_output.feature +40 -40
  72. data/testing/cucumber/features/modeling/directory_modeling.feature +62 -62
  73. data/testing/cucumber/features/modeling/directory_output.feature +33 -33
  74. data/testing/cucumber/features/modeling/doc_string_modeling.feature +85 -85
  75. data/testing/cucumber/features/modeling/doc_string_output.feature +50 -50
  76. data/testing/cucumber/features/modeling/example_modeling.feature +155 -155
  77. data/testing/cucumber/features/modeling/example_output.feature +57 -57
  78. data/testing/cucumber/features/modeling/feature_file_modeling.feature +49 -49
  79. data/testing/cucumber/features/modeling/feature_file_output.feature +33 -33
  80. data/testing/cucumber/features/modeling/feature_modeling.feature +149 -149
  81. data/testing/cucumber/features/modeling/feature_output.feature +144 -144
  82. data/testing/cucumber/features/modeling/model_output.feature +61 -61
  83. data/testing/cucumber/features/modeling/model_structure.feature +42 -42
  84. data/testing/cucumber/features/modeling/outline_modeling.feature +175 -175
  85. data/testing/cucumber/features/modeling/outline_output.feature +87 -87
  86. data/testing/cucumber/features/modeling/row_modeling.feature +70 -70
  87. data/testing/cucumber/features/modeling/row_output.feature +40 -40
  88. data/testing/cucumber/features/modeling/rule_modeling.feature +171 -171
  89. data/testing/cucumber/features/modeling/rule_output.feature +136 -136
  90. data/testing/cucumber/features/modeling/scenario_modeling.feature +146 -146
  91. data/testing/cucumber/features/modeling/scenario_output.feature +63 -63
  92. data/testing/cucumber/features/modeling/step_modeling.feature +105 -105
  93. data/testing/cucumber/features/modeling/step_output.feature +47 -47
  94. data/testing/cucumber/features/modeling/table_modeling.feature +73 -73
  95. data/testing/cucumber/features/modeling/table_output.feature +42 -42
  96. data/testing/cucumber/features/modeling/tag_modeling.feature +62 -62
  97. data/testing/cucumber/features/modeling/tag_output.feature +40 -40
  98. metadata +6 -8
@@ -1,178 +1,178 @@
1
- module CukeModeler
2
-
3
- # A class modeling a single step of a background, scenario, or outline.
4
- class Step < Model
5
-
6
- include Sourceable
7
- include Parsing
8
- include Parsed
9
-
10
-
11
- # The step's keyword
12
- attr_accessor :keyword
13
-
14
- # The base text of the step
15
- attr_accessor :text
16
-
17
- # The step's passed block
18
- attr_accessor :block
19
-
20
-
21
- # Creates a new Step object and, if *source_text* is provided, populates the
22
- # object.
23
- #
24
- # @example
25
- # Step.new
26
- # Step.new("Given a step")
27
- #
28
- # @param source_text [String] The Gherkin text that will be used to populate the model
29
- # @raise [ArgumentError] If *source_text* is not a String
30
- # @return [Step] A new Step instance
31
- def initialize(source_text = nil)
32
- super
33
- end
34
-
35
- # Compares this model with another object. Returns *true* if the two objects
36
- # have the same base text, table, and doc string and *false* otherwise.
37
- #
38
- # @example
39
- # step_1 == step_2
40
- #
41
- # @param other [Object] The object to compare this model with
42
- # @return [Boolean] Whether the two objects are equivalent
43
- def ==(other)
44
- return false unless other.is_a?(CukeModeler::Step)
45
-
46
- text_matches?(other) &&
47
- table_matches?(other) &&
48
- doc_string_matches?(other)
49
- end
50
-
51
- # Returns the model objects that are children of this model. For a
52
- # Step model, these would be any associated Table or DocString models.
53
- #
54
- # @example
55
- # step.children
56
- #
57
- # @return [Array<Table, DocString>] A collection of child models
58
- def children
59
- block ? [block] : []
60
- end
61
-
62
- # Returns a string representation of this model. For a Step model,
63
- # this will be Gherkin text that is equivalent to the step being modeled.
64
- #
65
- # @example
66
- # step.to_s
67
- #
68
- # @return [String] A string representation of this model
69
- def to_s
70
- text = "#{keyword} #{self.text}"
71
- text << "\n#{block.to_s.split("\n").collect { |line| " #{line}" }.join("\n")}" if block
72
-
73
- text
74
- end
75
-
76
- # See `Object#inspect`. Returns some basic information about the
77
- # object, including its class, object ID, and its most meaningful
78
- # attribute. For a Step model, this will be the text of the step.
79
- # If *verbose* is true, provides default Ruby inspection behavior
80
- # instead.
81
- #
82
- # @example
83
- # step.inspect
84
- # step.inspect(verbose: true)
85
- #
86
- # @param verbose [Boolean] Whether or not to return the full details of
87
- # the object. Defaults to false.
88
- # @return [String] A string representation of this model
89
- def inspect(verbose: false)
90
- return super if verbose
91
-
92
- "#{super.chop} @text: #{@text.inspect}>"
93
- end
94
-
95
-
96
- private
97
-
98
-
99
- def process_source(source_text)
100
- base_file_string = "# language: #{Parsing.dialect}
101
- #{dialect_feature_keyword}: Fake feature to parse
102
- #{dialect_scenario_keyword}:\n"
103
- source_text = base_file_string + source_text
104
-
105
- parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_step.feature')
106
-
107
- parsed_file['feature']['elements'].first['steps'].first
108
- end
109
-
110
- def populate_model(parsed_step_data)
111
- populate_text(parsed_step_data)
112
- populate_block(parsed_step_data)
113
- populate_keyword(parsed_step_data)
114
- populate_source_location(parsed_step_data)
115
- populate_parsing_data(parsed_step_data)
116
- end
117
-
118
- def populate_text(parsed_step_data)
119
- @text = parsed_step_data['name']
120
- end
121
-
122
- def populate_block(parsed_step_data)
123
- @block = if parsed_step_data['table']
124
- build_child_model(Table, parsed_step_data['table'])
125
- elsif parsed_step_data['doc_string']
126
- build_child_model(DocString, parsed_step_data['doc_string'])
127
- end
128
- end
129
-
130
- def text_matches?(other_step)
131
- text == other_step.text
132
- end
133
-
134
- def table_matches?(other_step)
135
- return false if only_one_step_has_table?(other_step)
136
- return true if neither_step_has_table?(other_step)
137
-
138
- first_step_values = block.rows.collect { |table_row| table_row.cells.map(&:value) }
139
- second_step_values = other_step.block.rows.collect { |table_row| table_row.cells.map(&:value) }
140
-
141
- first_step_values == second_step_values
142
- end
143
-
144
- def doc_string_matches?(other_step)
145
- return false if only_one_step_has_doc_string?(other_step)
146
- return true if neither_step_has_doc_string?(other_step)
147
-
148
- first_content = block.content
149
- first_content_type = block.content_type
150
- second_content = other_step.block.content
151
- second_content_type = other_step.block.content_type
152
-
153
- (first_content == second_content) &&
154
- (first_content_type == second_content_type)
155
- end
156
-
157
- def only_one_step_has_table?(other_step)
158
- (!block.is_a?(CukeModeler::Table) || !other_step.block.is_a?(CukeModeler::Table)) &&
159
- (block.is_a?(CukeModeler::Table) || other_step.block.is_a?(CukeModeler::Table))
160
- end
161
-
162
- def neither_step_has_table?(other_step)
163
- !block.is_a?(CukeModeler::Table) &&
164
- !other_step.block.is_a?(CukeModeler::Table)
165
- end
166
-
167
- def only_one_step_has_doc_string?(other_step)
168
- (!block.is_a?(CukeModeler::DocString) || !other_step.block.is_a?(CukeModeler::DocString)) &&
169
- (block.is_a?(CukeModeler::DocString) || other_step.block.is_a?(CukeModeler::DocString))
170
- end
171
-
172
- def neither_step_has_doc_string?(other_step)
173
- !block.is_a?(CukeModeler::DocString) &&
174
- !other_step.block.is_a?(CukeModeler::DocString)
175
- end
176
-
177
- end
178
- end
1
+ module CukeModeler
2
+
3
+ # A class modeling a single step of a background, scenario, or outline.
4
+ class Step < Model
5
+
6
+ include Sourceable
7
+ include Parsing
8
+ include Parsed
9
+
10
+
11
+ # The step's keyword
12
+ attr_accessor :keyword
13
+
14
+ # The base text of the step
15
+ attr_accessor :text
16
+
17
+ # The step's passed block
18
+ attr_accessor :block
19
+
20
+
21
+ # Creates a new Step object and, if *source_text* is provided, populates the
22
+ # object.
23
+ #
24
+ # @example
25
+ # Step.new
26
+ # Step.new("Given a step")
27
+ #
28
+ # @param source_text [String] The Gherkin text that will be used to populate the model
29
+ # @raise [ArgumentError] If *source_text* is not a String
30
+ # @return [Step] A new Step instance
31
+ def initialize(source_text = nil)
32
+ super
33
+ end
34
+
35
+ # Compares this model with another object. Returns *true* if the two objects
36
+ # have the same base text, table, and doc string and *false* otherwise.
37
+ #
38
+ # @example
39
+ # step_1 == step_2
40
+ #
41
+ # @param other [Object] The object to compare this model with
42
+ # @return [Boolean] Whether the two objects are equivalent
43
+ def ==(other)
44
+ return false unless other.is_a?(CukeModeler::Step)
45
+
46
+ text_matches?(other) &&
47
+ table_matches?(other) &&
48
+ doc_string_matches?(other)
49
+ end
50
+
51
+ # Returns the model objects that are children of this model. For a
52
+ # Step model, these would be any associated Table or DocString models.
53
+ #
54
+ # @example
55
+ # step.children
56
+ #
57
+ # @return [Array<Table, DocString>] A collection of child models
58
+ def children
59
+ block ? [block] : []
60
+ end
61
+
62
+ # Returns a string representation of this model. For a Step model,
63
+ # this will be Gherkin text that is equivalent to the step being modeled.
64
+ #
65
+ # @example
66
+ # step.to_s
67
+ #
68
+ # @return [String] A string representation of this model
69
+ def to_s
70
+ text = "#{keyword} #{self.text}"
71
+ text << "\n#{block.to_s.split("\n").collect { |line| " #{line}" }.join("\n")}" if block
72
+
73
+ text
74
+ end
75
+
76
+ # See `Object#inspect`. Returns some basic information about the
77
+ # object, including its class, object ID, and its most meaningful
78
+ # attribute. For a Step model, this will be the text of the step.
79
+ # If *verbose* is true, provides default Ruby inspection behavior
80
+ # instead.
81
+ #
82
+ # @example
83
+ # step.inspect
84
+ # step.inspect(verbose: true)
85
+ #
86
+ # @param verbose [Boolean] Whether or not to return the full details of
87
+ # the object. Defaults to false.
88
+ # @return [String] A string representation of this model
89
+ def inspect(verbose: false)
90
+ return super if verbose
91
+
92
+ "#{super.chop} @text: #{@text.inspect}>"
93
+ end
94
+
95
+
96
+ private
97
+
98
+
99
+ def process_source(source_text)
100
+ base_file_string = "# language: #{Parsing.dialect}
101
+ #{dialect_feature_keyword}: Fake feature to parse
102
+ #{dialect_scenario_keyword}:\n"
103
+ source_text = base_file_string + source_text
104
+
105
+ parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_step.feature')
106
+
107
+ parsed_file['feature']['elements'].first['steps'].first
108
+ end
109
+
110
+ def populate_model(parsed_step_data)
111
+ populate_text(parsed_step_data)
112
+ populate_block(parsed_step_data)
113
+ populate_keyword(parsed_step_data)
114
+ populate_source_location(parsed_step_data)
115
+ populate_parsing_data(parsed_step_data)
116
+ end
117
+
118
+ def populate_text(parsed_step_data)
119
+ @text = parsed_step_data['name']
120
+ end
121
+
122
+ def populate_block(parsed_step_data)
123
+ @block = if parsed_step_data['table']
124
+ build_child_model(Table, parsed_step_data['table'])
125
+ elsif parsed_step_data['doc_string']
126
+ build_child_model(DocString, parsed_step_data['doc_string'])
127
+ end
128
+ end
129
+
130
+ def text_matches?(other_step)
131
+ text == other_step.text
132
+ end
133
+
134
+ def table_matches?(other_step)
135
+ return false if only_one_step_has_table?(other_step)
136
+ return true if neither_step_has_table?(other_step)
137
+
138
+ first_step_values = block.rows.collect { |table_row| table_row.cells.map(&:value) }
139
+ second_step_values = other_step.block.rows.collect { |table_row| table_row.cells.map(&:value) }
140
+
141
+ first_step_values == second_step_values
142
+ end
143
+
144
+ def doc_string_matches?(other_step)
145
+ return false if only_one_step_has_doc_string?(other_step)
146
+ return true if neither_step_has_doc_string?(other_step)
147
+
148
+ first_content = block.content
149
+ first_content_type = block.content_type
150
+ second_content = other_step.block.content
151
+ second_content_type = other_step.block.content_type
152
+
153
+ (first_content == second_content) &&
154
+ (first_content_type == second_content_type)
155
+ end
156
+
157
+ def only_one_step_has_table?(other_step)
158
+ (!block.is_a?(CukeModeler::Table) || !other_step.block.is_a?(CukeModeler::Table)) &&
159
+ (block.is_a?(CukeModeler::Table) || other_step.block.is_a?(CukeModeler::Table))
160
+ end
161
+
162
+ def neither_step_has_table?(other_step)
163
+ !block.is_a?(CukeModeler::Table) &&
164
+ !other_step.block.is_a?(CukeModeler::Table)
165
+ end
166
+
167
+ def only_one_step_has_doc_string?(other_step)
168
+ (!block.is_a?(CukeModeler::DocString) || !other_step.block.is_a?(CukeModeler::DocString)) &&
169
+ (block.is_a?(CukeModeler::DocString) || other_step.block.is_a?(CukeModeler::DocString))
170
+ end
171
+
172
+ def neither_step_has_doc_string?(other_step)
173
+ !block.is_a?(CukeModeler::DocString) &&
174
+ !other_step.block.is_a?(CukeModeler::DocString)
175
+ end
176
+
177
+ end
178
+ end
@@ -1,117 +1,117 @@
1
- module CukeModeler
2
-
3
- # A class modeling a step's table.
4
- class Table < Model
5
-
6
- include Parsing
7
- include Parsed
8
- include Sourceable
9
-
10
-
11
- # The row models that make up the table
12
- attr_accessor :rows
13
-
14
-
15
- # Creates a new Table object and, if *source_text* is provided, populates
16
- # the object.
17
- #
18
- # @example
19
- # Table.new
20
- # Table.new("|value_1|value_2|\n|value_3|value_4|")
21
- #
22
- # @param source_text [String] The Gherkin text that will be used to populate the model
23
- # @raise [ArgumentError] If *source_text* is not a String
24
- # @return [Table] A new Table instance
25
- def initialize(source_text = nil)
26
- @rows = []
27
-
28
- super
29
- end
30
-
31
- # Returns the model objects that are children of this model. For a
32
- # Table model, these would be any associated Row models.
33
- #
34
- # @example
35
- # table.children
36
- #
37
- # @return [Array<Row>] A collection of child models
38
- def children
39
- rows
40
- end
41
-
42
- # Returns a string representation of this model. For a Table model,
43
- # this will be Gherkin text that is equivalent to the table being modeled.
44
- #
45
- # @example
46
- # table.to_s
47
- #
48
- # @return [String] A string representation of this model
49
- def to_s
50
- rows.empty? ? '' : rows.collect { |row| row_output_string(row) }.join("\n")
51
- end
52
-
53
- # See `Object#inspect`. Returns some basic information about the
54
- # object, including its class, object ID, and its most meaningful
55
- # attribute. For a Table model, this will be the rows of the table.
56
- # If *verbose* is true, provides default Ruby inspection behavior
57
- # instead.
58
- #
59
- # @example
60
- # table.inspect
61
- # table.inspect(verbose: true)
62
- #
63
- # @param verbose [Boolean] Whether or not to return the full details of
64
- # the object. Defaults to false.
65
- # @return [String] A string representation of this model
66
- def inspect(verbose: false)
67
- return super if verbose
68
-
69
- row_output = @rows&.collect { |row| row.cells.collect(&:value) }
70
-
71
- "#{super.chop} @rows: #{row_output.inspect}>"
72
- end
73
-
74
-
75
- private
76
-
77
-
78
- def process_source(source_text)
79
- base_file_string = "# language: #{Parsing.dialect}
80
- #{dialect_feature_keyword}:
81
- #{dialect_scenario_keyword}:
82
- #{dialect_step_keyword} step\n"
83
- source_text = base_file_string + source_text
84
-
85
- parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_table.feature')
86
-
87
- parsed_file['feature']['elements'].first['steps'].first['table']
88
- end
89
-
90
- def populate_model(parsed_table_data)
91
- populate_row_models(parsed_table_data)
92
- populate_parsing_data(parsed_table_data)
93
- populate_source_location(parsed_table_data)
94
- end
95
-
96
- def populate_row_models(parsed_table_data)
97
- parsed_table_data['rows'].each do |row_data|
98
- @rows << build_child_model(Row, row_data)
99
- end
100
- end
101
-
102
- def row_output_string(row)
103
- row_text = '|'
104
-
105
- row.cells.count.times do |count|
106
- row_text << " #{row.cells[count].to_s.ljust(determine_buffer_size(count))} |"
107
- end
108
-
109
- row_text
110
- end
111
-
112
- def determine_buffer_size(index)
113
- rows.collect { |row| row.cells[index].to_s.length }.max || 0
114
- end
115
-
116
- end
117
- end
1
+ module CukeModeler
2
+
3
+ # A class modeling a step's table.
4
+ class Table < Model
5
+
6
+ include Parsing
7
+ include Parsed
8
+ include Sourceable
9
+
10
+
11
+ # The row models that make up the table
12
+ attr_accessor :rows
13
+
14
+
15
+ # Creates a new Table object and, if *source_text* is provided, populates
16
+ # the object.
17
+ #
18
+ # @example
19
+ # Table.new
20
+ # Table.new("|value_1|value_2|\n|value_3|value_4|")
21
+ #
22
+ # @param source_text [String] The Gherkin text that will be used to populate the model
23
+ # @raise [ArgumentError] If *source_text* is not a String
24
+ # @return [Table] A new Table instance
25
+ def initialize(source_text = nil)
26
+ @rows = []
27
+
28
+ super
29
+ end
30
+
31
+ # Returns the model objects that are children of this model. For a
32
+ # Table model, these would be any associated Row models.
33
+ #
34
+ # @example
35
+ # table.children
36
+ #
37
+ # @return [Array<Row>] A collection of child models
38
+ def children
39
+ rows
40
+ end
41
+
42
+ # Returns a string representation of this model. For a Table model,
43
+ # this will be Gherkin text that is equivalent to the table being modeled.
44
+ #
45
+ # @example
46
+ # table.to_s
47
+ #
48
+ # @return [String] A string representation of this model
49
+ def to_s
50
+ rows.empty? ? '' : rows.collect { |row| row_output_string(row) }.join("\n")
51
+ end
52
+
53
+ # See `Object#inspect`. Returns some basic information about the
54
+ # object, including its class, object ID, and its most meaningful
55
+ # attribute. For a Table model, this will be the rows of the table.
56
+ # If *verbose* is true, provides default Ruby inspection behavior
57
+ # instead.
58
+ #
59
+ # @example
60
+ # table.inspect
61
+ # table.inspect(verbose: true)
62
+ #
63
+ # @param verbose [Boolean] Whether or not to return the full details of
64
+ # the object. Defaults to false.
65
+ # @return [String] A string representation of this model
66
+ def inspect(verbose: false)
67
+ return super if verbose
68
+
69
+ row_output = @rows&.collect { |row| row.cells.collect(&:value) }
70
+
71
+ "#{super.chop} @rows: #{row_output.inspect}>"
72
+ end
73
+
74
+
75
+ private
76
+
77
+
78
+ def process_source(source_text)
79
+ base_file_string = "# language: #{Parsing.dialect}
80
+ #{dialect_feature_keyword}:
81
+ #{dialect_scenario_keyword}:
82
+ #{dialect_step_keyword} step\n"
83
+ source_text = base_file_string + source_text
84
+
85
+ parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_table.feature')
86
+
87
+ parsed_file['feature']['elements'].first['steps'].first['table']
88
+ end
89
+
90
+ def populate_model(parsed_table_data)
91
+ populate_row_models(parsed_table_data)
92
+ populate_parsing_data(parsed_table_data)
93
+ populate_source_location(parsed_table_data)
94
+ end
95
+
96
+ def populate_row_models(parsed_table_data)
97
+ parsed_table_data['rows'].each do |row_data|
98
+ @rows << build_child_model(Row, row_data)
99
+ end
100
+ end
101
+
102
+ def row_output_string(row)
103
+ row_text = '|'
104
+
105
+ row.cells.count.times do |count|
106
+ row_text << " #{row.cells[count].to_s.ljust(determine_buffer_size(count))} |"
107
+ end
108
+
109
+ row_text
110
+ end
111
+
112
+ def determine_buffer_size(index)
113
+ rows.collect { |row| row.cells[index].to_s.length }.max || 0
114
+ end
115
+
116
+ end
117
+ end