Sha256: e372fe4634043bc10ca323d5f4751b3db9f5956c650df51ba88f8eb0719ec8b1

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'multi_json'
module MetricFu
  class Grapher

    @graphers = []
    # @return all subclassed graphers [Array<MetricFu::Grapher>]
    def self.graphers
      @graphers
    end

    def self.inherited(subclass)
      @graphers << subclass
    end

    def self.get_grapher(metric)
      graphers.find{|grapher|grapher.metric.to_s == metric.to_s}
    end

    attr_accessor :output_directory

    def initialize(opts = {})
      self.output_directory = opts[:output_directory]
    end

    def output_directory
      @output_directory || MetricFu::Io::FileSystem.directory('output_directory')
    end

    def get_metrics(metrics, sortable_prefix)
      not_implemented
    end

    def graph!
      labels = MultiJson.dump(@labels)
      content = <<-EOS
        var graph_title = '#{title}';
        #{build_data(data)}
        var graph_labels = #{labels};
      EOS
      File.open(File.join(self.output_directory, output_filename), 'w') {|f| f << content }
    end

    def title
      not_implemented
    end

    def date
      not_implemented
    end

    def output_filename
      not_implemented
    end

    private

    def build_data(data)
      'var graph_series = [' << Array(data).map do |label, datum|
        "{name: '#{label}', data: [#{datum}]}"
      end.join(",") << '];'
    end

    def not_implemented
      raise "#{__LINE__} in #{__FILE__} from #{caller[0]}"
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metric_fu-4.11.3 lib/metric_fu/reporting/graphs/grapher.rb
metric_fu-4.11.2 lib/metric_fu/reporting/graphs/grapher.rb
metric_fu-4.11.1 lib/metric_fu/reporting/graphs/grapher.rb
metric_fu-4.11.0 lib/metric_fu/reporting/graphs/grapher.rb
metric_fu-4.10.0 lib/metric_fu/reporting/graphs/grapher.rb
metric_fu-4.9.0 lib/metric_fu/reporting/graphs/grapher.rb