Class: MetricFu::Graph
- Inherits:
-
Object
- Object
- MetricFu::Graph
- Defined in:
- lib/base/graph.rb
Instance Attribute Summary collapse
-
#clazz ⇒ Object
Returns the value of attribute clazz.
Instance Method Summary collapse
- #add(graph_type, graph_engine) ⇒ Object
- #generate ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
11 12 13 |
# File 'lib/base/graph.rb', line 11 def initialize self.clazz = [] end |
Instance Attribute Details
#clazz ⇒ Object
Returns the value of attribute clazz.
9 10 11 |
# File 'lib/base/graph.rb', line 9 def clazz @clazz end |
Instance Method Details
#add(graph_type, graph_engine) ⇒ Object
15 16 17 18 |
# File 'lib/base/graph.rb', line 15 def add(graph_type, graph_engine) grapher_name = graph_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } + graph_engine.to_s.capitalize + "Grapher" self.clazz.push MetricFu.const_get(grapher_name).new end |
#generate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/base/graph.rb', line 21 def generate return if self.clazz.empty? puts "Generating graphs" Dir[File.join(MetricFu.data_directory, '*.yml')].sort.each do |metric_file| puts "Generating graphs for #{metric_file}" date_parts = year_month_day_from_filename(metric_file) metrics = YAML::load(File.open(metric_file)) self.clazz.each do |grapher| grapher.get_metrics(metrics, "#{date_parts[:m]}/#{date_parts[:d]}") end end self.clazz.each do |grapher| grapher.graph! end end |