Class: GruffBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_velocity/gruff_builder.rb

Constant Summary collapse

MIN_VALUE =
0
MAX_VALUE =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, relative_path, versions, gem_name, gruff_options = {}) ⇒ GruffBuilder

Returns a new instance of GruffBuilder.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#gem_nameObject

Returns the value of attribute gem_name.



13
14
15
# File 'lib/gem_velocity/gruff_builder.rb', line 13

def gem_name
  @gem_name
end

#hide_legendObject

Returns the value of attribute hide_legend.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def hide_legend
  @hide_legend
end

#labelsObject

Returns the value of attribute labels.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def labels
  @labels
end

#line_datasObject

Returns the value of attribute line_datas.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def line_datas
  @line_datas
end

#max_valueObject

Returns the value of attribute max_value.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def max_value
  @max_value
end

#min_valueObject

Returns the value of attribute min_value.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def min_value
  @min_value
end

#relative_pathObject

Returns the value of attribute relative_path.



13
14
15
# File 'lib/gem_velocity/gruff_builder.rb', line 13

def relative_path
  @relative_path
end

#rootObject

Returns the value of attribute root.



13
14
15
# File 'lib/gem_velocity/gruff_builder.rb', line 13

def root
  @root
end

#titleObject

Returns the value of attribute title.



14
15
16
# File 'lib/gem_velocity/gruff_builder.rb', line 14

def title
  @title
end

#versionsObject

Returns the value of attribute versions.



13
14
15
# File 'lib/gem_velocity/gruff_builder.rb', line 13

def versions
  @versions
end

Instance Method Details

#absolute_filenameObject



39
40
41
# File 'lib/gem_velocity/gruff_builder.rb', line 39

def absolute_filename
  "#{absolute_destination}/#{filename}"
end

#filenameObject



35
36
37
# File 'lib/gem_velocity/gruff_builder.rb', line 35

def filename
  "#{graph_name(@type, versions.join("-"))}.png"
end

#relative_filenameObject



31
32
33
# File 'lib/gem_velocity/gruff_builder.rb', line 31

def relative_filename
  "#{@relative_path}#{filename}"
end

#writeObject

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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