Class: Cuker::SummaryXLModel

Inherits:
RubyXLModel show all
Defined in:
lib/cuker/helpers/formatters/summary_x_l_model.rb

Constant Summary collapse

EXCEL_BLANK =
nil

Constants inherited from RubyXLModel

RubyXLModel::EXCEL_EMPTY_LINE, RubyXLModel::EXCEL_HORIZ_RULER, RubyXLModel::EXCEL_NEW_LINE, RubyXLModel::EXCEL_OFFSET, RubyXLModel::EXCEL_ROW_SEP, RubyXLModel::EXCEL_TITLE_SEP, RubyXLModel::TITLE_MAX_LEN

Constants included from ExcelSupport

ExcelSupport::EXCEL_TABLE_PADDING

Constants inherited from AbstractModel

AbstractModel::AND, AbstractModel::BACKGROUND, AbstractModel::BUT, AbstractModel::EXAMPLES, AbstractModel::FEATURE, AbstractModel::GIVEN, AbstractModel::SCENARIO, AbstractModel::SCENARIO_OUTLINE, AbstractModel::THEN, AbstractModel::WHEN

Instance Attribute Summary

Attributes inherited from RubyXLModel

#special_tag_list

Attributes included from LoggerSetup

#log

Attributes inherited from AbstractModel

#data, #title

Instance Method Summary collapse

Methods inherited from RubyXLModel

#get_examples, #get_step_args, #get_steps, #get_table_cell, #get_table_row, #get_title_ary, #in_item, #in_step

Methods included from ExcelSupport

#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

Methods included from StringHelper

#add_newlines, #add_newlines!, #add_newlines_regex

Methods included from LoggerSetup

#init_logger, reset_appender_log_levels

Methods inherited from AbstractModel

#get_keys_ary, #get_tags, #get_values_ary, #name_merge, #simple_surround, #surround, #union

Methods included from Interface

#method

Constructor Details

#initialize(ast_map, tags_list) ⇒ SummaryXLModel

Returns a new instance of SummaryXLModel.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 6

def initialize ast_map, tags_list
  init_logger

  @log.trace "initing #{self.class}"
  @log.debug "has #{ast_map.size} items"

  @asts = ast_map

  @special_tag_list = tags_list
  # special_tag_titles

  @order = make_order
  @title = make_title @order
  @data = make_rows
end

Instance Method Details

#example_count(example_ary) ⇒ Object



187
188
189
190
191
192
193
194
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 187

def example_count example_ary
  # [0] title
  # [1] table = [[0] title [...] examples]
  # [2] blank
  sum = []
  (1..example_ary.size).step(3).each {|i| sum << (example_ary[i].size - 1)}
  sum.inject('+')
end

#filter_special_tags(all_tags) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 49

def filter_special_tags(all_tags)
  return [[], all_tags] unless special_tags
  ignore_list = all_tags - special_tags
  select_list = all_tags - ignore_list
  ordered_list = []
  special_tag_titles.each {|tag| ordered_list << (select_list.include?(tag) ? tag : EXCEL_BLANK)}
  [ordered_list, ignore_list, select_list]
end

#in_feature(hsh) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 172

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}
    yield feat_tags, feat_title, nil if children.empty?
  else
    @log.warn "No Features found in file @ #{@file_path}"
  end
end

#make_orderObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 22

def make_order
  [
      {:counter => "Sl.No"},
      {:s_type => "Type"},
      {:s_title => "Title"},
      {:tags => special_tag_titles},
      {:other_tags => "Other Tags"},
      {:feature_title => "Feature Title"},
      {:feature_count => "Feature"},
      {:bg_title => "Background"},
      {:file_s_num => "Scen.no"},
      {:file_name => "File"},
  ]
end

#make_rowsObject



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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 58

def make_rows
  if @asts.nil? or @asts.empty?
    @log.debug "No asts to parse!"
    return []
  end

  feat_counter = 0
  feature_title = []
  feature_tags_ary = []
  bg_title = []
  bg_tags_ary = []

  res = []
  @asts.each do |file_path, ast|
    @log.debug "Understanding file: #{file_path}"
    @file_path = file_path
    in_feat_counter = 0
    @no_feature_content = false

    if ast[:type] == :GherkinDocument
      # feat_counter += 1
      if ast[:feature]
        in_feature(ast) do |feat_tags_ary, feat_title, feat_item|
          @no_feature_content = true
          if feat_item
            in_item(feat_item) do |tags_ary, type, item_title, content_ary, example_ary|
              feature_title = feat_title
              feature_tags_ary = feat_tags_ary
              if type == :Background or type == :Feature
                # bg_title = [excel_title(BACKGROUND, item_title)] + content_ary
                bg_title = item_title
                bg_tags_ary = tags_ary
                next
              end
                row_hsh = {}
                # if type == :Scenario or type == :ScenarioOutline
                # scen_title = [excel_title(type.to_s, item_title)] + content_ary
                scen_title = item_title

                row_hsh[:counter] = feat_counter += 1
                row_hsh[:s_type] = type == :Scenario ? "S" : "SO"
                row_hsh[:s_title] = excel_content_format scen_title

                all_tags = [feat_tags_ary, bg_tags_ary, tags_ary].flatten.compact
                ordered_list, ignore_list, select_list = filter_special_tags(all_tags)
                row_hsh[:tags] = ordered_list
                row_hsh[:other_tags] = ignore_list.join ", "
                row_hsh[:feature_title] = excel_content_format feature_title
                row_hsh[:bg_title] = excel_content_format bg_title
                row_hsh[:file_s_num] = in_feat_counter += 1
                row_hsh[:feature_count] = in_feat_counter == 1 ? 1 : 0
                row_hsh[:file_name] = file_path

                # row_hsh[:examples] = "" # is nil by default
                if type == :ScenarioOutline
                  row_hsh[:examples] = example_count example_ary
                end
                row_ary = []
                get_keys_ary(@order).each do |k|
                  if k == :tags
                    # v.each { |tag| row_ary << (tag.nil?? EXCEL_BLANK : tag) }
                    tags_ary = row_hsh[k]
                    tags_ary.each {|tag| row_ary << tag}
                  else
                    row_ary << (row_hsh[k])
                  end
                end
                res << row_ary
                @no_feature_content = false
              # end
              # get_keys_ary(@order).each {|k| row_ary << excel_arg_hilight(row_hsh[k])}
            end
          end

        end

        if @no_feature_content
          @log.warn "No 'Scenario:' or 'Scenario Outline:' found in file @ #{@file_path}"

          row_hsh = {}
          feat_counter += 1

          row_hsh[:bg_title] = excel_content_format bg_title
          row_hsh[:feature_title] = excel_content_format feature_title
          row_hsh[:file_s_num] = in_feat_counter += 1
          row_hsh[:feature_count] = in_feat_counter == 1 ? 1 : 0
          all_tags = [feature_tags_ary, bg_tags_ary].flatten.compact
          ordered_list, ignore_list, select_list = filter_special_tags(all_tags)
          row_hsh[:tags] = ordered_list
          row_hsh[:other_tags] = ignore_list.join ", "

          write_empty_row res, row_hsh, feat_counter, file_path
        end

        feature_title = []
        feature_tags_ary = []
        bg_title = []
        bg_tags_ary = []

      else
        # todo: blank feature fill!
        @log.warn "No 'Feature:' found in file @ #{@file_path}"

        row_hsh = {}
        feat_counter += 1

        write_empty_row res, row_hsh, feat_counter, file_path
      end
    end
  end
  @file_path = nil
  res
end

#make_title(order) ⇒ Object



37
38
39
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 37

def make_title order
  get_values_ary order
end

#special_tag_titlesObject



41
42
43
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 41

def special_tag_titles
  @special_tag_titles ||= @special_tag_list if @special_tag_list
end

#special_tagsObject



45
46
47
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 45

def special_tags
  @special_tags ||= @special_tag_list if @special_tag_list
end

#write_empty_row(res, row_hsh, feat_counter, file_path) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/cuker/helpers/formatters/summary_x_l_model.rb', line 196

def write_empty_row res, row_hsh, feat_counter, file_path
  row_hsh[:feature_count] ||= 0
  row_hsh[:file_s_num] ||= 0
  row_hsh[:counter] = feat_counter
  row_hsh[:s_type] = nil
  row_hsh[:file_name] = file_path
  row_hsh[:tags] = Array.new(@special_tag_list.size)

  row_ary = []
  get_keys_ary(@order).each do |k|
    if k == :tags
      tags_ary = row_hsh[k]
      tags_ary.each {|tag| row_ary << tag}
    else
      row_ary << (row_hsh[k])
    end
  end
  res << row_ary
  @no_feature_content = false
end