Module: Snuffle::Formatters::Base

Included in:
Csv, Html, HtmlIndex, Text
Defined in:
lib/snuffle/formatters/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



7
8
9
10
# File 'lib/snuffle/formatters/base.rb', line 7

def self.included(klass)
  klass.send(:attr_accessor, :summary)
  klass.send(:attr_accessor, :source)
end

Instance Method Details

#columnsObject



21
22
23
# File 'lib/snuffle/formatters/base.rb', line 21

def columns
  ["filename", "host class", "candidate object attributes", "source line numbers"]
end

#contentObject



17
18
19
# File 'lib/snuffle/formatters/base.rb', line 17

def content
  [header, rows, footer].flatten.join("\r\n")
end

#exportObject



49
50
51
52
53
54
# File 'lib/snuffle/formatters/base.rb', line 49

def export
  outfile = File.open("#{path_to_results}", 'w')
  outfile.write(content)
  outfile.close
  path_to_results
end

#file_extensionObject



45
46
47
# File 'lib/snuffle/formatters/base.rb', line 45

def file_extension
  ""
end

#filenameObject



41
42
43
# File 'lib/snuffle/formatters/base.rb', line 41

def filename
  "#{summary.filename}" + file_extension
end

#initialize(summary, source = "") ⇒ Object



12
13
14
15
# File 'lib/snuffle/formatters/base.rb', line 12

def initialize(summary, source="")
  self.summary = summary
  self.source = source
end

#output_pathObject



29
30
31
32
33
34
35
# File 'lib/snuffle/formatters/base.rb', line 29

def output_path
  return @output_path if @output_path
  path = root_path
  path << "/" + summary.path_to_results if summary
  FileUtils.mkpath(path)
  @output_path = path
end

#path_to_resultsObject



37
38
39
# File 'lib/snuffle/formatters/base.rb', line 37

def path_to_results
  "#{output_path}/#{filename}"
end

#root_pathObject



25
26
27
# File 'lib/snuffle/formatters/base.rb', line 25

def root_path
  "doc/snuffle"
end