Class: ChurnVsComplexity::Normal::Serializer::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/churn_vs_complexity/normal/serializer/graph.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template: Graph.load_template_file) ⇒ Graph

Returns a new instance of Graph.



7
8
9
# File 'lib/churn_vs_complexity/normal/serializer/graph.rb', line 7

def initialize(template: Graph.load_template_file)
  @template = template
end

Class Method Details

.load_template_fileObject



19
20
21
22
# File 'lib/churn_vs_complexity/normal/serializer/graph.rb', line 19

def self.load_template_file
  file_path = File.join(ROOT_PATH, 'tmp/template/graph.html')
  File.read(file_path)
end

Instance Method Details

#serialize(result) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/churn_vs_complexity/normal/serializer/graph.rb', line 11

def serialize(result)
  data = result[:values_by_file].map do |file, values|
    "{ file_path: '#{file}', churn: #{values[0]}, complexity: #{values[1]} }"
  end.join(",\n") + "\n"
  title = Serializer.title(result)
  @template.gsub("// INSERT DATA\n", data).gsub('INSERT TITLE', title)
end