class GruffBuilder

Constants

MAX_VALUE
MIN_VALUE

Attributes

gem_name[RW]
hide_legend[RW]
labels[RW]
line_datas[RW]
max_value[RW]
min_value[RW]
relative_path[RW]
root[RW]
title[RW]
versions[RW]

Public Class Methods

new(root, relative_path, versions, gem_name, gruff_options = {}) click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 16
def initialize(root, relative_path, versions, gem_name, gruff_options = {})
  # just pass it in all in gruff_options?
  @root           = root || raise(ArgumentError,"you must set a root. default is root/public/images")
  @relative_path  = relative_path || "public/images/"
  @versions       = versions.is_a?(Array) ? versions : raise(ArgumentError,"versions must be an array")
  @gem_name       = gem_name
  @title          = gruff_options[:title] || ""
  @labels         = gruff_options[:labels] || {}
  @line_datas     = gruff_options[:line_datas]
  @min_value      = gruff_options[:min_value] || MIN_VALUE
  @max_value      = gruff_options[:max_value] || MAX_VALUE
  @hide_legend    = gruff_options[:hide_legend] || false
  @type           = gruff_options[:type]
end

Public Instance Methods

absolute_filename() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 39
def absolute_filename
  "#{absolute_destination}/#{filename}"
end
filename() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 35
def filename
  "#{graph_name(@type, versions.join("-"))}.png"
end
relative_filename() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 31
def relative_filename
  "#{@relative_path}#{filename}"
end
write() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 43
def write
  raise NoData if @line_datas.nil? || @line_datas.empty?
  ensure_destination
  gruff.title = @title
  gruff.labels = @labels
  @line_datas.each_with_index do |line_data,index|
    gruff.data graph_name(@versions[index]), line_data
  end
  gruff.minimum_value = @min_value
  gruff.maximum_value = @max_value
  gruff.hide_legend = @hide_legend
  gruff.write(absolute_filename)
  absolute_filename
end

Private Instance Methods

absolute_destination() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 60
def absolute_destination
  File.expand_path(File.join(@root, @relative_path))
end
ensure_destination() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 64
def ensure_destination
  FileUtils.mkdir_p(File.expand_path(absolute_destination))
end
graph_name(prepend_text = nil, append_text = nil) click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 68
def graph_name(prepend_text = nil, append_text = nil)
  prepend_text = prepend_text.nil? ? "" : "#{prepend_text}-"
  append_text = append_text.nil? ? "" : "-#{append_text}"
  prepend_text + "#{gem_name}"+ append_text
end
gruff() click to toggle source
# File lib/gem_velocity/gruff_builder.rb, line 74
def gruff
  @gruff ||= Gruff::Line.new
end