Class: ChurnVsComplexity::Normal::Serializer::Graph
- Inherits:
-
Object
- Object
- ChurnVsComplexity::Normal::Serializer::Graph
- Defined in:
- lib/churn_vs_complexity/normal/serializer/graph.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template: Graph.load_template_file) ⇒ Graph
constructor
A new instance of Graph.
- #serialize(result) ⇒ Object
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_file ⇒ Object
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 |