Class: Cuker::RubyXLModel
Defined Under Namespace
Modules: EXCEL_CONSTS
Classes: Identifier
Constant Summary
collapse
- TITLE_MAX_LEN =
60
- EXCEL_BLANK =
''
- EXCEL_TITLE_SEP =
'|'
- EXCEL_ROW_SEP =
'|'
- EXCEL_EMPTY_LINE =
' '
- EXCEL_NEW_LINE =
"\n"
- EXCEL_HORIZ_RULER =
' '
- EXCEL_OFFSET =
6
ExcelSupport::EXCEL_TABLE_PADDING
AbstractModel::AND, AbstractModel::BACKGROUND, AbstractModel::BUT, AbstractModel::EXAMPLES, AbstractModel::FEATURE, AbstractModel::GIVEN, AbstractModel::SCENARIO, AbstractModel::SCENARIO_OUTLINE, AbstractModel::THEN, AbstractModel::WHEN
Instance Attribute Summary collapse
Attributes included from LoggerSetup
#log
#data, #title
Instance Method Summary
collapse
#excel_arg_hilight, #excel_blank_pad, #excel_bold, #excel_bold_italics, #excel_content_format, #excel_italics, #excel_monospace, #excel_title, #surround_color, #surround_panel, #tableify
#add_newlines, #add_newlines!, #add_newlines_regex
#init_logger, reset_appender_log_levels
#get_keys_ary, #get_tags, #get_values_ary, #name_merge, #simple_surround, #surround, #union
Methods included from Interface
#method
Constructor Details
#initialize(ast_map) ⇒ RubyXLModel
Returns a new instance of RubyXLModel.
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 109
def initialize ast_map
super
@log.trace "initing #{self.class}"
@log.debug "has #{ast_map.size} items"
@asts = ast_map
@order = make_order
@title = make_title @order
@data = make_rows
end
|
Instance Attribute Details
#special_tag_list ⇒ Object
Returns the value of attribute special_tag_list.
96
97
98
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 96
def special_tag_list
@special_tag_list
end
|
Instance Method Details
152
153
154
155
156
157
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 152
def filter_special_tags(all_tags)
return [[], all_tags] unless special_tag_lookup
ignore_list = all_tags - special_tag_lookup
select_list = all_tags - ignore_list
[select_list, ignore_list]
end
|
#get_examples(examples) ⇒ Object
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 299
def get_examples(examples)
res = []
examples.each do |example|
if example[:type] == :Examples
example_data = []
eg_title = excel_title EXAMPLES, get_title_ary(example)
res << eg_title
= example[:tableHeader]
= .nil? ? [] : get_table_row()
example_data <<
eg_body = example[:tableBody]
eg_body.map {|row_hsh| example_data << get_table_row(row_hsh)} unless eg_body.nil?
res << tableify(example_data)
res << EXCEL_HORIZ_RULER
else
@log.debug "Unknown type '#{example[:type]}' found in file @ #{@file_path}"
end
end
res
end
|
#get_step_args(arg) ⇒ Object
helps handle tables for now
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 269
def get_step_args arg
if arg[:type] == :DataTable
res = []
arg[:rows].each_with_index do |row, i|
res << row[:cells].map {|hsh| hsh[:value]}
end
return res
elsif arg[:type] == :DocString
@log.debug "Docstrings found in '#{arg}' found in file @ #{@file_path}"
else
@log.debug "Unknown type '#{arg[:type]}' found in file @ #{@file_path}"
end
[]
end
|
#get_steps(hsh) ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 287
def get_steps(hsh)
if hsh[:steps] and hsh[:steps].any?
content = []
steps = hsh[:steps]
in_step(steps) {|step| content += step}
content
else
@log.debug "No Tags found in #{hsh[:keyword]} @ #{@file_path}"
[]
end
end
|
#get_table_cell(cell_hsh) ⇒ Object
334
335
336
337
338
339
340
341
342
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 334
def get_table_cell cell_hsh
if cell_hsh[:type] == :TableCell
val = cell_hsh[:value].strip
val.empty? ? EXCEL_BLANK : val
else
@log.debug "Expected :TableCell in '#{cell_hsh}' @ #{@file_path}"
EXCEL_BLANK
end
end
|
#get_table_row(row_hsh) ⇒ Object
325
326
327
328
329
330
331
332
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 325
def get_table_row row_hsh
if row_hsh[:type] == :TableRow
row_hsh[:cells].map(&method(:get_table_cell))
else
@log.debug "Expected :TableRow in '#{row_hsh}' @ #{@file_path}"
[]
end
end
|
#get_title_ary(hsh, max_len = TITLE_MAX_LEN) ⇒ Object
344
345
346
347
348
349
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 344
def get_title_ary hsh, max_len = TITLE_MAX_LEN
title_ary = []
title_ary << hsh[:name].strip.force_encoding("UTF-8") if hsh[:name]
title_ary << hsh[:description].strip.force_encoding("UTF-8") if hsh[:description]
title_ary
end
|
#in_feature(hsh) ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 215
def in_feature(hsh)
if hsh[:feature]
feat = hsh[:feature]
feat_tags = get_tags feat
feat_title = get_title_ary feat
children = feat[:children]
children.each {|child| yield feat_tags, feat_title, child}
else
@log.debug "No Features found in file @ #{@file_path}"
end
end
|
#in_item(child) ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 229
def in_item(child)
item_title = get_title_ary child
tags = get_tags child
if child[:type] == :Background
yield tags, child[:type], item_title, get_steps(child), []
elsif child[:type] == :Scenario
yield tags, child[:type], item_title, get_steps(child), []
elsif child[:type] == :ScenarioOutline
yield tags, child[:type], item_title, get_steps(child), get_examples(child[:examples])
else
@log.debug "Unknown type '#{child[:type]}' found in file @ #{@file_path}"
end
end
|
#in_step(steps) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 247
def in_step(steps)
steps.each do |step|
if step[:type] == :Step
step_ary = []
step_str = [
((excel_bold(step[:keyword].strip)).rjust(EXCEL_OFFSET)), (step[:text].strip)
].join(' ')
step_ary << (step_str)
step_ary += tableify(get_step_args(step[:argument]), EXCEL_TABLE_PADDING) if step[:argument]
yield step_ary
else
@log.debug "Unknown type '#{item[:type]}' found in file @ #{@file_path}"
end
end
end
|
#make_order ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 123
def make_order
[
{:counter => "Sl.No"},
{:feature => "Feature"},
{:background => "Background"},
{:scenario => "Scenario"},
{:examples => "Examples"},
{:result => "Result"},
{:tested_by => "Tested By"},
{:test_designer => "Test Designer"},
{:comments => "Comments"},
]
end
|
#make_rows ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 159
def make_rows
if @asts.nil? or @asts.empty?
@log.debug "No asts to parse!"
return []
end
feat_counter = 1
feat_content = []
bg_content = []
res = []
@asts.each do |file_path, ast|
@log.debug "Understanding file: #{file_path}"
@file_path = file_path
in_feat_counter = 0
if ast[:type] == :GherkinDocument
in_feature(ast) do |feat_tags_ary, feat_title, feat_item|
in_item(feat_item) do |tags_ary, type, item_title, content_ary, example_ary|
row_hsh = {}
feat_content = excel_title FEATURE, feat_title
if type == :Background or type == :Feature
bg_content = [excel_title(BACKGROUND, item_title)] + content_ary
else
scen_content = [excel_title(type.to_s, item_title)] + content_ary
row_hsh[:counter] = "#{feat_counter}.#{in_feat_counter += 1}"
row_hsh[:feature] = excel_content_format feat_content
row_hsh[:background] = excel_content_format bg_content
row_hsh[:scenario] = excel_content_format scen_content
row_hsh[:result] = EXCEL_CONSTS::RESULT::PENDING
row_hsh[:tested_by] = ""
row_hsh[:test_designer] = ""
row_hsh[:comments] = ""
if type == :ScenarioOutline
row_hsh[:examples] = excel_content_format example_ary
end
row_ary = []
get_keys_ary(@order).each {|k| row_ary << (row_hsh[k])}
res << row_ary
end
end
end
end
feat_counter += 1
feat_title = []
bg_content = []
end
@file_path = nil
res
end
|
#make_title(order) ⇒ Object
140
141
142
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 140
def make_title order
get_values_ary order
end
|
#special_tag_lookup ⇒ Object
148
149
150
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 148
def special_tag_lookup
@special_tag_lookup ||= get_keys_ary @special_tag_list if @special_tag_list
end
|
#special_tag_titles ⇒ Object
144
145
146
|
# File 'lib/cuker/helpers/formatters/ruby_x_l_model.rb', line 144
def special_tag_titles
@special_tag_titles ||= get_values_ary @special_tag_list if @special_tag_list
end
|