Class: ReportGraphGenerator

Inherits:
Object show all
Defined in:
lib/tdriver/report/report_graph_generator.rb

Overview

Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Nokia Corporation ([email protected])

This file is part of Testability Driver.

If you have questions regarding the use of this file, please contact Nokia at [email protected] .

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation and appearing in the file LICENSE.LGPL included in the packaging of this file.

Instance Method Summary collapse

Constructor Details

#initialize(columns, data) ⇒ ReportGraphGenerator

Returns a new instance of ReportGraphGenerator.



21
22
23
24
# File 'lib/tdriver/report/report_graph_generator.rb', line 21

def initialize(columns,data)
  @columns=columns
  @data=data
end

Instance Method Details

#generate_graph(file_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tdriver/report/report_graph_generator.rb', line 26

def generate_graph(file_name)

  begin
    require 'gruff'
  rescue LoadError
    $stderr.puts "Can't load the Gruff gem. If its missing from your system please run 'gem install gruff' to install it."
  end

  begin
    g = Gruff::Line.new()
                
    data_rows = Hash.new #Create hash for data
    @columns.each do |title|        
      data_rows[title] = Array.new #Create array for data
    end
                      
    @data.each do |value|        
      value.each_key do |key|
        data_rows[key].push(value[key].to_f) #Put values in the row data
      end
    end
    
    data_rows.each_key do |key|
      g.data(key, data_rows[key])
    end
    
    g.write(file_name)

  rescue Exception => e
    puts "Graph creation failed #{e.message} from data: "
    p data_rows
  end
end