cuke_modeler 3.20.0 → 3.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/README.md +5 -6
  4. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +5 -5
  5. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +5 -5
  6. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +5 -5
  7. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +5 -5
  8. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +5 -5
  9. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +5 -5
  10. data/lib/cuke_modeler/adapters/gherkin_16_adapter.rb +5 -5
  11. data/lib/cuke_modeler/adapters/gherkin_17_adapter.rb +5 -5
  12. data/lib/cuke_modeler/adapters/gherkin_18_adapter.rb +5 -2
  13. data/lib/cuke_modeler/adapters/gherkin_19_adapter.rb +5 -2
  14. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +5 -2
  15. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +5 -5
  16. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +5 -5
  17. data/lib/cuke_modeler/adapters/gherkin_23_adapter.rb +5 -5
  18. data/lib/cuke_modeler/adapters/gherkin_24_adapter.rb +5 -5
  19. data/lib/cuke_modeler/adapters/gherkin_25_adapter.rb +5 -5
  20. data/lib/cuke_modeler/adapters/gherkin_26_adapter.rb +5 -5
  21. data/lib/cuke_modeler/adapters/gherkin_27_adapter.rb +5 -5
  22. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +5 -2
  23. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +5 -2
  24. data/lib/cuke_modeler/containing.rb +43 -210
  25. data/lib/cuke_modeler/described.rb +8 -4
  26. data/lib/cuke_modeler/models/background.rb +53 -11
  27. data/lib/cuke_modeler/models/cell.rb +36 -8
  28. data/lib/cuke_modeler/models/comment.rb +35 -8
  29. data/lib/cuke_modeler/models/directory.rb +58 -10
  30. data/lib/cuke_modeler/models/doc_string.rb +41 -9
  31. data/lib/cuke_modeler/models/example.rb +94 -17
  32. data/lib/cuke_modeler/models/feature.rb +73 -11
  33. data/lib/cuke_modeler/models/feature_file.rb +56 -12
  34. data/lib/cuke_modeler/models/model.rb +50 -7
  35. data/lib/cuke_modeler/models/outline.rb +59 -10
  36. data/lib/cuke_modeler/models/row.rb +45 -9
  37. data/lib/cuke_modeler/models/rule.rb +59 -9
  38. data/lib/cuke_modeler/models/scenario.rb +51 -10
  39. data/lib/cuke_modeler/models/step.rb +61 -11
  40. data/lib/cuke_modeler/models/table.rb +45 -9
  41. data/lib/cuke_modeler/models/tag.rb +30 -14
  42. data/lib/cuke_modeler/named.rb +7 -4
  43. data/lib/cuke_modeler/nested.rb +19 -4
  44. data/lib/cuke_modeler/parsed.rb +10 -5
  45. data/lib/cuke_modeler/parsing.rb +25 -13
  46. data/lib/cuke_modeler/sourceable.rb +11 -5
  47. data/lib/cuke_modeler/stepped.rb +7 -5
  48. data/lib/cuke_modeler/taggable.rb +22 -4
  49. data/lib/cuke_modeler/version.rb +1 -1
  50. data/testing/cucumber/features/modeling/base_model.feature +3 -0
  51. metadata +3 -2
@@ -1,17 +1,26 @@
1
- # It's the module that has functionality for every possible model type. So, yes, it's long.
2
- # rubocop:disable Metrics/ModuleLength
3
-
4
1
  module CukeModeler
5
2
 
6
- # NOT A PART OF THE PUBLIC API
7
- # A mix-in module containing methods used by models that contain other models.
3
+ # @api private
4
+ #
5
+ # A mix-in module containing methods used by models that contain other models. Internal helper class.
8
6
  module Containing
9
7
 
10
8
  include Enumerable
11
9
 
10
+ # TODO: Have this method return `self` so that method chaining can be done?
11
+
12
+ # @api
13
+ #
12
14
  # Executes the given code block with this model and every model that is a child of this model. Exact
13
15
  # order of model tree traversal is not guaranteed beyond the first model traversed, which will be the
14
16
  # model that called this method. If no block is provided, an `Enumerator` is returned instead.
17
+ #
18
+ # @example
19
+ # model.each
20
+ # model.each { |model| puts model.inspect }
21
+ #
22
+ # @yieldparam [Model] The current model being visited
23
+ # @return [Enumerable] if no block is given
15
24
  def each(&block)
16
25
  if block
17
26
  block.call(self)
@@ -21,8 +30,15 @@ module CukeModeler
21
30
  end
22
31
  end
23
32
 
33
+ # @api
34
+ # @deprecated Use `Enumerable` module methods instead
35
+ #
24
36
  # Executes the given code block with every model that is a child of this model.
25
- # DEPRECATED: use `Enumerable` module methods instead
37
+ #
38
+ # @example
39
+ # model.each_descendant { |model| puts model.inspect }
40
+ #
41
+ # @yieldparam [Model] The current model being visited
26
42
  def each_descendant(&block)
27
43
  children.each do |child_model|
28
44
  block.call(child_model)
@@ -30,8 +46,15 @@ module CukeModeler
30
46
  end
31
47
  end
32
48
 
49
+ # @api
50
+ # @deprecated Use `Enumerable` module methods instead
51
+ #
33
52
  # Executes the given code block with this model and every model that is a child of this model.
34
- # DEPRECATED: use `Enumerable` module methods instead
53
+ #
54
+ # @example
55
+ # model.each_model { |model| puts model.inspect }
56
+ #
57
+ # @yieldparam [Model] The current model being visited
35
58
  def each_model(&block)
36
59
  block.call(self)
37
60
 
@@ -44,229 +67,39 @@ module CukeModeler
44
67
 
45
68
  def build_child_model(clazz, model_data)
46
69
  model = clazz.new
47
-
48
- tiny_class = clazz.name.match(/::(\w+)/)[1].downcase
49
- model.send("populate_#{tiny_class}", model, model_data)
50
-
70
+ # Send-ing to get around private scoping. Don't want the make the method public
71
+ # and there is no way to get the already processed data to the child model that
72
+ # wouldn't require something public.
73
+ model.send('populate_model', model_data)
51
74
  model.parent_model = self
52
75
 
53
76
  model
54
77
  end
55
78
 
56
- def populate_scenario(scenario_object, parsed_scenario_data)
57
- populate_parsing_data(scenario_object, parsed_scenario_data)
58
- populate_source_location(scenario_object, parsed_scenario_data)
59
- populate_keyword(scenario_object, parsed_scenario_data)
60
- populate_name(scenario_object, parsed_scenario_data)
61
- populate_description(scenario_object, parsed_scenario_data)
62
- populate_steps(scenario_object, parsed_scenario_data)
63
- populate_tags(scenario_object, parsed_scenario_data)
64
- end
65
-
66
- def populate_outline(outline_object, parsed_outline_data)
67
- populate_parsing_data(outline_object, parsed_outline_data)
68
- populate_source_location(outline_object, parsed_outline_data)
69
- populate_keyword(outline_object, parsed_outline_data)
70
- populate_name(outline_object, parsed_outline_data)
71
- populate_description(outline_object, parsed_outline_data)
72
- populate_steps(outline_object, parsed_outline_data)
73
- populate_tags(outline_object, parsed_outline_data)
74
- populate_outline_examples(outline_object, parsed_outline_data['examples']) if parsed_outline_data['examples']
75
- end
76
-
77
- def populate_background(background_object, parsed_background_data)
78
- populate_parsing_data(background_object, parsed_background_data)
79
- populate_keyword(background_object, parsed_background_data)
80
- populate_name(background_object, parsed_background_data)
81
- populate_description(background_object, parsed_background_data)
82
- populate_source_location(background_object, parsed_background_data)
83
- populate_steps(background_object, parsed_background_data)
84
- end
85
-
86
- def populate_step(step_object, parsed_step_data)
87
- populate_text(step_object, parsed_step_data)
88
- populate_block(step_object, parsed_step_data)
89
- populate_keyword(step_object, parsed_step_data)
90
- populate_source_location(step_object, parsed_step_data)
91
- populate_parsing_data(step_object, parsed_step_data)
92
- end
93
-
94
- def populate_block(step_object, parsed_step_data)
95
- step_object.block = if parsed_step_data['table']
96
- build_child_model(Table, parsed_step_data['table'])
97
- elsif parsed_step_data['doc_string']
98
- build_child_model(DocString, parsed_step_data['doc_string'])
99
- end
100
- end
101
-
102
- def populate_table(table_object, parsed_table_data)
103
- populate_row_models(table_object, parsed_table_data)
104
- populate_parsing_data(table_object, parsed_table_data)
105
- populate_source_location(table_object, parsed_table_data)
106
- end
107
-
108
- def populate_cell(cell_object, parsed_cell_data)
109
- populate_cell_value(cell_object, parsed_cell_data)
110
- populate_source_location(cell_object, parsed_cell_data)
111
- populate_parsing_data(cell_object, parsed_cell_data)
112
- end
113
-
114
- def populate_docstring(doc_string_object, parsed_doc_string_data)
115
- populate_content_type(doc_string_object, parsed_doc_string_data)
116
- populate_content(doc_string_object, parsed_doc_string_data)
117
- populate_parsing_data(doc_string_object, parsed_doc_string_data)
118
- populate_source_location(doc_string_object, parsed_doc_string_data)
79
+ # TODO: move to mix-in module
80
+ def populate_keyword(parsed_model_data)
81
+ @keyword = parsed_model_data['keyword'].strip
119
82
  end
120
83
 
121
- def populate_example(example_object, parsed_example_data)
122
- populate_parsing_data(example_object, parsed_example_data)
123
- populate_keyword(example_object, parsed_example_data)
124
- populate_source_location(example_object, parsed_example_data)
125
- populate_name(example_object, parsed_example_data)
126
- populate_description(example_object, parsed_example_data)
127
- populate_tags(example_object, parsed_example_data)
128
- populate_example_rows(example_object, parsed_example_data)
129
- end
130
-
131
- def populate_row(row_object, parsed_row_data)
132
- populate_source_location(row_object, parsed_row_data)
133
- populate_row_cells(row_object, parsed_row_data)
134
- populate_parsing_data(row_object, parsed_row_data)
135
- end
136
-
137
- def populate_feature(feature_object, parsed_feature_data)
138
- populate_parsing_data(feature_object, parsed_feature_data)
139
- populate_source_location(feature_object, parsed_feature_data)
140
- populate_language(feature_object, parsed_feature_data)
141
- populate_keyword(feature_object, parsed_feature_data)
142
- populate_name(feature_object, parsed_feature_data)
143
- populate_description(feature_object, parsed_feature_data)
144
- populate_tags(feature_object, parsed_feature_data)
145
- populate_children(feature_object, parsed_feature_data)
146
- end
147
-
148
- def populate_rule(rule_object, parsed_rule_data)
149
- populate_parsing_data(rule_object, parsed_rule_data)
150
- populate_source_location(rule_object, parsed_rule_data)
151
- populate_keyword(rule_object, parsed_rule_data)
152
- populate_name(rule_object, parsed_rule_data)
153
- populate_description(rule_object, parsed_rule_data)
154
- populate_tags(rule_object, parsed_rule_data)
155
- populate_children(rule_object, parsed_rule_data)
156
- end
157
-
158
- def populate_directory(directory_object, processed_directory_data)
159
- directory_object.path = processed_directory_data['path']
160
-
161
- processed_directory_data['directories'].each do |directory_data|
162
- directory_object.directories << build_child_model(Directory, directory_data)
163
- end
164
-
165
- processed_directory_data['feature_files'].each do |feature_file_data|
166
- directory_object.feature_files << build_child_model(FeatureFile, feature_file_data)
167
- end
168
- end
169
-
170
- def populate_featurefile(feature_file_object, processed_feature_file_data)
171
- populate_parsing_data(feature_file_object, processed_feature_file_data)
172
- feature_file_object.path = processed_feature_file_data['path']
173
-
174
- if processed_feature_file_data['feature']
175
- feature_file_object.feature = build_child_model(Feature, processed_feature_file_data['feature'])
176
- end
177
-
178
- processed_feature_file_data['comments'].each do |comment_data|
179
- feature_file_object.comments << build_child_model(Comment, comment_data)
180
- end
181
- end
182
-
183
- def populate_tag(tag_object, processed_tag_data)
184
- populate_name(tag_object, processed_tag_data)
185
- populate_parsing_data(tag_object, processed_tag_data)
186
- populate_source_location(tag_object, processed_tag_data)
187
- end
188
-
189
- def populate_comment(comment_object, processed_comment_data)
190
- populate_comment_text(comment_object, processed_comment_data)
191
- populate_parsing_data(comment_object, processed_comment_data)
192
- populate_source_location(comment_object, processed_comment_data)
193
- end
194
-
195
- def populate_language(feature_model, parsed_feature_data)
196
- feature_model.language = parsed_feature_data['language']
197
- end
198
-
199
- def populate_comment_text(comment_model, parsed_comment_data)
200
- comment_model.text = parsed_comment_data['text'].strip
201
- end
202
-
203
- def populate_text(step_model, parsed_step_data)
204
- step_model.text = parsed_step_data['name']
205
- end
206
-
207
- def populate_keyword(model, parsed_model_data)
208
- model.keyword = parsed_model_data['keyword'].strip
209
- end
210
-
211
- def populate_row_models(table_model, parsed_table_data)
212
- parsed_table_data['rows'].each do |row_data|
213
- table_model.rows << build_child_model(Row, row_data)
214
- end
215
- end
216
-
217
- def populate_row_cells(row_model, parsed_row_data)
218
- parsed_row_data['cells'].each do |cell_data|
219
- row_model.cells << build_child_model(Cell, cell_data)
220
- end
221
- end
222
-
223
- def populate_cell_value(cell_model, parsed_cell_data)
224
- cell_model.value = parsed_cell_data['value']
225
- end
226
-
227
- def populate_content_type(doc_string_model, parsed_doc_string_data)
228
- doc_string_model.content_type = parsed_doc_string_data['content_type']
229
- end
230
-
231
- def populate_content(doc_string_model, parsed_doc_string_data)
232
- doc_string_model.content = parsed_doc_string_data['value']
233
- end
234
-
235
- def populate_outline_examples(outline_model, parsed_examples)
236
- parsed_examples.each do |example_data|
237
- outline_model.examples << build_child_model(Example, example_data)
238
- end
239
- end
240
-
241
- def populate_example_rows(example_model, parsed_example_data)
242
- parsed_example_data['rows'].each do |row_data|
243
- example_model.rows << build_child_model(Row, row_data)
244
- end
245
- end
246
-
247
- # It's not getting better any time soon
248
- # rubocop:disable Metrics/AbcSize
249
-
250
- def populate_children(model, parsed_feature_data)
84
+ # TODO: move elsewhere?
85
+ def populate_children(parsed_feature_data)
251
86
  return unless parsed_feature_data['elements']
252
87
 
253
88
  parsed_feature_data['elements'].each do |element|
254
89
  case element['type']
255
90
  when 'Scenario', 'scenario'
256
- model.tests << build_child_model(Scenario, element)
91
+ @tests << build_child_model(Scenario, element)
257
92
  when 'ScenarioOutline', 'scenario_outline'
258
- model.tests << build_child_model(Outline, element)
93
+ @tests << build_child_model(Outline, element)
259
94
  when 'Background', 'background'
260
- model.background = build_child_model(Background, element)
95
+ @background = build_child_model(Background, element)
261
96
  when 'Rule'
262
- model.rules << build_child_model(Rule, element)
97
+ @rules << build_child_model(Rule, element)
263
98
  else
264
99
  raise(ArgumentError, "Unknown element type: #{element['type']}")
265
100
  end
266
101
  end
267
102
  end
268
- # rubocop:enable Metrics/AbcSize
269
103
 
270
104
  end
271
105
  end
272
- # rubocop:enable Metrics/ModuleLength
@@ -1,9 +1,13 @@
1
1
  module CukeModeler
2
2
 
3
- # NOT A PART OF THE PUBLIC API
4
- # A mix-in module containing methods used by models that represent an element that has a description.
3
+ # @api private
4
+ #
5
+ # A mix-in module containing methods used by models that represent an element that has a
6
+ # description. Internal helper class.
5
7
  module Described
6
8
 
9
+ # @api
10
+ #
7
11
  # The description of the element
8
12
  attr_accessor :description
9
13
 
@@ -28,8 +32,8 @@ module CukeModeler
28
32
  description.nil? || description.empty?
29
33
  end
30
34
 
31
- def populate_description(model, parsed_model_data)
32
- model.description = trimmed_description(parsed_model_data['description'])
35
+ def populate_description(parsed_model_data)
36
+ @description = trimmed_description(parsed_model_data['description'])
33
37
  end
34
38
 
35
39
  def trimmed_description(description)
@@ -17,31 +17,55 @@ module CukeModeler
17
17
 
18
18
  # Creates a new Background object and, if *source_text* is provided, populates
19
19
  # the object.
20
+ #
21
+ # @example
22
+ # Background.new
23
+ # Background.new("Background:\n * a step")
24
+ #
25
+ # @param source_text [String] The Gherkin text that will be used to populate the model
26
+ # @raise [ArgumentError] If *source_text* is not a String
27
+ # @return [Background] A new Background instance
20
28
  def initialize(source_text = nil)
21
29
  @steps = []
22
30
 
23
31
  super(source_text)
24
-
25
- return unless source_text
26
-
27
- parsed_background_data = parse_source(source_text)
28
- populate_background(self, parsed_background_data)
29
32
  end
30
33
 
31
- # Returns *true* if the two models have equivalent steps and *false* otherwise.
34
+ # TODO: Have (all) models be equivalent if they have the same #to_s output. Would
35
+ # likely require major version change.
36
+
37
+ # Compares this model with another object. Returns *true* if the two objects
38
+ # have equivalent steps and *false* otherwise.
39
+ #
40
+ # @example
41
+ # background_1 == background_2
42
+ #
43
+ # @param other [Object] The object to compare this model with
44
+ # @return [Boolean] Whether the two objects are equivalent
32
45
  def ==(other)
33
46
  return false unless other.respond_to?(:steps)
34
47
 
35
48
  steps == other.steps
36
49
  end
37
50
 
38
- # Returns the model objects that belong to this model.
51
+ # Returns the model objects that are children of this model. For a
52
+ # Background model, these would be any associated Step models.
53
+ #
54
+ # @example
55
+ # background.children
56
+ #
57
+ # @return [Array<Step>] A collection of child models
39
58
  def children
40
59
  steps
41
60
  end
42
61
 
43
- # Returns a string representation of this model. For a background model,
62
+ # Returns a string representation of this model. For a Background model,
44
63
  # this will be Gherkin text that is equivalent to the background being modeled.
64
+ #
65
+ # @example
66
+ # background.to_s
67
+ #
68
+ # @return [String] A string representation of this model
45
69
  def to_s
46
70
  text = ''
47
71
 
@@ -55,8 +79,17 @@ module CukeModeler
55
79
 
56
80
  # See `Object#inspect`. Returns some basic information about the
57
81
  # object, including its class, object ID, and its most meaningful
58
- # attribute. For a background model, this will be the name of the
59
- # background.
82
+ # attribute. For a Background model, this will be the name of the
83
+ # background. If *verbose* is true, provides default Ruby inspection
84
+ # behavior instead.
85
+ #
86
+ # @example
87
+ # background.inspect
88
+ # background.inspect(verbose: true)
89
+ #
90
+ # @param verbose [Boolean] Whether or not to return the full details of
91
+ # the object. Defaults to false.
92
+ # @return [String] A string representation of this model
60
93
  def inspect(verbose: false)
61
94
  return super(verbose: verbose) if verbose
62
95
 
@@ -67,7 +100,7 @@ module CukeModeler
67
100
  private
68
101
 
69
102
 
70
- def parse_source(source_text)
103
+ def process_source(source_text)
71
104
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
72
105
  source_text = base_file_string + source_text
73
106
 
@@ -76,5 +109,14 @@ module CukeModeler
76
109
  parsed_file['feature']['elements'].first
77
110
  end
78
111
 
112
+ def populate_model(parsed_background_data)
113
+ populate_parsing_data(parsed_background_data)
114
+ populate_keyword(parsed_background_data)
115
+ populate_name(parsed_background_data)
116
+ populate_description(parsed_background_data)
117
+ populate_source_location(parsed_background_data)
118
+ populate_steps(parsed_background_data)
119
+ end
120
+
79
121
  end
80
122
  end
@@ -14,17 +14,25 @@ module CukeModeler
14
14
 
15
15
  # Creates a new Cell object and, if *source_text* is provided, populates
16
16
  # the object.
17
+ #
18
+ # @example
19
+ # Cell.new
20
+ # Cell.new('some value')
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 [Cell] A new Cell instance
17
25
  def initialize(source_text = nil)
18
26
  super(source_text)
19
-
20
- return unless source_text
21
-
22
- parsed_cell_data = parse_source(source_text)
23
- populate_cell(self, parsed_cell_data)
24
27
  end
25
28
 
26
- # Returns a string representation of this model. For a cell model,
29
+ # Returns a string representation of this model. For a Cell model,
27
30
  # this will be Gherkin text that is equivalent to the cell being modeled.
31
+ #
32
+ # @example
33
+ # cell.to_s
34
+ #
35
+ # @return [String] A string representation of this model
28
36
  def to_s
29
37
  # Vertical bars and backslashes are special characters that need to be escaped
30
38
  @value ? @value.gsub('\\', '\\\\\\').gsub('|', '\|') : ''
@@ -32,7 +40,17 @@ module CukeModeler
32
40
 
33
41
  # See `Object#inspect`. Returns some basic information about the
34
42
  # object, including its class, object ID, and its most meaningful
35
- # attribute. For a cell model, this will be the value of the cell.
43
+ # attribute. For a Cell model, this will be the value of the
44
+ # cell. If *verbose* is true, provides default Ruby inspection
45
+ # behavior instead.
46
+ #
47
+ # @example
48
+ # cell.inspect
49
+ # cell.inspect(verbose: true)
50
+ #
51
+ # @param verbose [Boolean] Whether or not to return the full details of
52
+ # the object. Defaults to false.
53
+ # @return [String] A string representation of this model
36
54
  def inspect(verbose: false)
37
55
  return super(verbose: verbose) if verbose
38
56
 
@@ -43,7 +61,7 @@ module CukeModeler
43
61
  private
44
62
 
45
63
 
46
- def parse_source(source_text)
64
+ def process_source(source_text)
47
65
  base_file_string = "# language: #{Parsing.dialect}
48
66
  #{dialect_feature_keyword}: Fake feature to parse
49
67
  #{dialect_scenario_keyword}:
@@ -55,6 +73,16 @@ module CukeModeler
55
73
  parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first['cells'].first
56
74
  end
57
75
 
76
+ def populate_model(parsed_cell_data)
77
+ populate_cell_value(parsed_cell_data)
78
+ populate_source_location(parsed_cell_data)
79
+ populate_parsing_data(parsed_cell_data)
80
+ end
81
+
82
+ def populate_cell_value(parsed_cell_data)
83
+ @value = parsed_cell_data['value']
84
+ end
85
+
58
86
  end
59
87
 
60
88
  end
@@ -14,24 +14,41 @@ module CukeModeler
14
14
 
15
15
  # Creates a new Comment object and, if *source_text* is provided, populates the
16
16
  # object.
17
+ #
18
+ # @example
19
+ # Comment.new
20
+ # Comment.new('# A comment')
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 [Comment] A new Comment instance
17
25
  def initialize(source_text = nil)
18
26
  super(source_text)
19
-
20
- return unless source_text
21
-
22
- parsed_comment_data = parse_source(source_text)
23
- populate_comment(self, parsed_comment_data)
24
27
  end
25
28
 
26
- # Returns a string representation of this model. For a comment model,
29
+ # Returns a string representation of this model. For a Comment model,
27
30
  # this will be Gherkin text that is equivalent to the comment being modeled.
31
+ #
32
+ # @example
33
+ # comment.to_s
34
+ #
35
+ # @return [String] A string representation of this model
28
36
  def to_s
29
37
  text || ''
30
38
  end
31
39
 
32
40
  # See `Object#inspect`. Returns some basic information about the
33
41
  # object, including its class, object ID, and its most meaningful
34
- # attribute. For a comment model, this will be the text of the comment.
42
+ # attribute. For a Comment model, this will be the text of the comment.
43
+ # If *verbose* is true, provides default Ruby inspection behavior instead.
44
+ #
45
+ # @example
46
+ # comment.inspect
47
+ # comment.inspect(verbose: true)
48
+ #
49
+ # @param verbose [Boolean] Whether or not to return the full details of
50
+ # the object. Defaults to false.
51
+ # @return [String] A string representation of this model
35
52
  def inspect(verbose: false)
36
53
  return super(verbose: verbose) if verbose
37
54
 
@@ -42,7 +59,7 @@ module CukeModeler
42
59
  private
43
60
 
44
61
 
45
- def parse_source(source_text)
62
+ def process_source(source_text)
46
63
  base_file_string = "\n#{dialect_feature_keyword}: Fake feature to parse"
47
64
  source_text = "# language: #{Parsing.dialect}\n" + source_text + base_file_string
48
65
 
@@ -51,5 +68,15 @@ module CukeModeler
51
68
  parsed_file['comments'].last
52
69
  end
53
70
 
71
+ def populate_model(processed_comment_data)
72
+ populate_comment_text(processed_comment_data)
73
+ populate_parsing_data(processed_comment_data)
74
+ populate_source_location(processed_comment_data)
75
+ end
76
+
77
+ def populate_comment_text(parsed_comment_data)
78
+ @text = parsed_comment_data['text'].strip
79
+ end
80
+
54
81
  end
55
82
  end