Class: SuiteView

Inherits:
Object
  • Object
show all
Defined in:
lib/suiteview.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SuiteView

Returns a new instance of SuiteView.



5
6
7
8
9
# File 'lib/suiteview.rb', line 5

def initialize(opts)
  self.output = nil
  self.repo = CQL::Repository.new(opts[:repo])
  self.include_tags = opts[:include_tags]
end

Instance Attribute Details

#include_tagsObject

Returns the value of attribute include_tags.



4
5
6
# File 'lib/suiteview.rb', line 4

def include_tags
  @include_tags
end

#outputObject

Returns the value of attribute output.



4
5
6
# File 'lib/suiteview.rb', line 4

def output
  @output
end

#repoObject

Returns the value of attribute repo.



4
5
6
# File 'lib/suiteview.rb', line 4

def repo
  @repo
end

Instance Method Details

#outline_tag_count(tag) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/suiteview.rb', line 11

def outline_tag_count(tag)
  self.output = self.repo.query do
    select examples
    transform examples => lambda {|examples| examples[0].rows.drop(1) }
    from outlines
    with { |outline| outline.tags.map(&:name).include?(tag)}
  end.map {|item| item['examples']}.flatten.count
  self
end

#percentagesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/suiteview.rb', line 44

def percentages
  output = [%w(tag percent)]
  total_count = 0
  tag_counts = {}
  self.include_tags.split(',').each do |include_tag|
    total_count += total_tag_count(include_tag).render
    tag_counts[include_tag] = total_tag_count(include_tag).render
  end
  self.include_tags.split(',').each do |include_tag|
    output << [include_tag, ((tag_counts[include_tag]/total_count.to_f)*100).to_s]
  end
  self.output = output
  self
end

#renderObject



68
69
70
# File 'lib/suiteview.rb', line 68

def render
  self.output
end

#render_to_file(filename) ⇒ Object



72
73
74
75
76
# File 'lib/suiteview.rb', line 72

def render_to_file(filename)
  File.open(filename, "w") do |f|
    f.puts self.output
  end
end

#scenario_tag_count(tag) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/suiteview.rb', line 21

def scenario_tag_count(tag)
  self.output = self.repo.query do
    select name
    from scenarios
    with { |scenario| scenario.tags.map(&:name).include?(tag)}
  end.map {|item| item['name']}.count
  self
end

#to_csvObject



59
60
61
62
63
64
65
66
# File 'lib/suiteview.rb', line 59

def to_csv
  self.output = CSV.generate do |csv|
    self.output.each do |row|
      csv << row
    end
  end
  self
end

#total_tag_count(tag) ⇒ Object



30
31
32
33
# File 'lib/suiteview.rb', line 30

def total_tag_count(tag)
  self.output = scenario_tag_count(tag).render + outline_tag_count(tag).render
  self
end

#total_tags_countObject



35
36
37
38
39
40
41
42
# File 'lib/suiteview.rb', line 35

def total_tags_count
  output = [%w(tag count)]
  self.include_tags.split(',').each do |tag|
    output << [tag, total_tag_count(tag).render.to_s]
  end
  self.output = output
  self
end