Class: Cuporter::Formatter::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/cuporter/formatter/writer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, output, number_scenarios) ⇒ Writer

Returns a new instance of Writer.



9
10
11
12
13
# File 'lib/cuporter/formatter/writer.rb', line 9

def initialize(report, output, number_scenarios)
  @report = report
  @output = output ? File.open(output, "w") : STDOUT
  @number_scenarios = number_scenarios
end

Instance Attribute Details

#number_scenariosObject (readonly)

Returns the value of attribute number_scenarios.



7
8
9
# File 'lib/cuporter/formatter/writer.rb', line 7

def number_scenarios
  @number_scenarios
end

Class Method Details

.create(format, report, output, number_scenarios) ⇒ Object



15
16
17
18
# File 'lib/cuporter/formatter/writer.rb', line 15

def self.create(format, report, output, number_scenarios)
  klass = writer_class(format, report.class.name.split(/::/).last)
  klass.new(report, output, number_scenarios)
end

.writer_class(format, report_class) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cuporter/formatter/writer.rb', line 20

def self.writer_class(format, report_class)
  fmt = case format
  when /text|pretty/i 
    "Text"
  when /csv/i
    "Csv"
  when /html/i
    "Html"
  end
  Cuporter::Formatter.const_get(report_class).const_get(fmt)
end