Class: Turbulence::Generators::TreeMap
- Inherits:
-
Object
- Object
- Turbulence::Generators::TreeMap
- Defined in:
- lib/turbulence/generators/treemap.rb
Instance Attribute Summary collapse
-
#metrics_hash ⇒ Object
readonly
Returns the value of attribute metrics_hash.
-
#x_metric ⇒ Object
readonly
Returns the value of attribute x_metric.
-
#y_metric ⇒ Object
readonly
Returns the value of attribute y_metric.
Instance Method Summary collapse
- #build_js ⇒ Object
- #generate_results(metrics, cli) ⇒ Object
-
#initialize(metrics_hash, x_metric = Turbulence::Calculators::Churn, y_metric = Turbulence::Calculators::Complexity) ⇒ TreeMap
constructor
A new instance of TreeMap.
Constructor Details
#initialize(metrics_hash, x_metric = Turbulence::Calculators::Churn, y_metric = Turbulence::Calculators::Complexity) ⇒ TreeMap
Returns a new instance of TreeMap.
6 7 8 9 10 11 12 |
# File 'lib/turbulence/generators/treemap.rb', line 6 def initialize(metrics_hash, x_metric = Turbulence::Calculators::Churn, y_metric = Turbulence::Calculators::Complexity) @x_metric = x_metric @y_metric = y_metric @metrics_hash = metrics_hash end |
Instance Attribute Details
#metrics_hash ⇒ Object (readonly)
Returns the value of attribute metrics_hash.
4 5 6 |
# File 'lib/turbulence/generators/treemap.rb', line 4 def metrics_hash @metrics_hash end |
#x_metric ⇒ Object (readonly)
Returns the value of attribute x_metric.
4 5 6 |
# File 'lib/turbulence/generators/treemap.rb', line 4 def x_metric @x_metric end |
#y_metric ⇒ Object (readonly)
Returns the value of attribute y_metric.
4 5 6 |
# File 'lib/turbulence/generators/treemap.rb', line 4 def y_metric @y_metric end |
Instance Method Details
#build_js ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/turbulence/generators/treemap.rb', line 21 def build_js clean_metrics_from_missing_data output = "var treemap_data = [['File', 'Parent', 'Churn (size)', 'Complexity (color)'],\n" output << "['Root', null, 0, 0],\n" @metrics_hash.each do |file| output << "['#{file[0]}', 'Root', #{file[1][@x_metric]}, #{file[1][@y_metric]}],\n" end output << "];" output end |
#generate_results(metrics, cli) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/turbulence/generators/treemap.rb', line 14 def generate_results(metrics, cli) File.open("treemap_data.js", "w") do |f| cli.copy_templates_into(Dir.pwd) f.write Turbulence::Generators::TreeMap.from(metrics).build_js end end |