class SoPerf::RenderJob

Attributes

duration[RW]
each_space_values[RW]
longest_name[RW]
names[RW]
pretty_tick_values[RW]
raw_duration[RW]
scale[RW]
scaled_tick_locations[RW]
spacer[RW]
tick_frequency[RW]
tick_locations[RW]
use_color[RW]
width[RW]

Public Class Methods

new(options_hash) click to toggle source
# File lib/soperf/render_job.rb, line 12
def initialize(options_hash)
  options = default_render_options.merge(options_hash)
  raise StandardError if options[:duration].nil?

  @names                 = options[:names]
  @spacer                = options[:spacer]
  @use_color             = options[:color]
  @width                 = options.has_key?(:width) ? options[:width] : usable_space(terminal_width, options[:longest_name])
  puts terminal_width
  @raw_duration          = options[:duration]
  @duration              = ((options[:duration]/10.0).ceil*10)
  @scale                 = @width/@duration.to_f
  @tick_frequency        = tick_frequency
  @pretty_tick_values    = pretty_tick_values
  @tick_locations        = tick_locations
  @each_space_values     = values_for_each_space
  @scaled_tick_locations = scaled_tick_locations
  @longest_name          = options[:longest_name]
end

Public Instance Methods

default_render_options() click to toggle source
# File lib/soperf/render_job.rb, line 32
def default_render_options
  { duration:     nil,
    longest_name: 0,
    color:        true,
    summary:      true,
    spacer:       Spacer.new }
end
usable_space(base_width, longest_name) click to toggle source
# File lib/soperf/render_job.rb, line 79
def usable_space(base_width, longest_name) #Space for the chart,
  base_width - longest_name - 10 #accounting for printing row names
end
values_for_each_space() click to toggle source
# File lib/soperf/render_job.rb, line 40
def values_for_each_space
  result = []
  count  = 0
  (@width+1).times do
    result << count
    count += @duration/@width.to_f
  end
  @pretty_tick_values.each do |val|
    index         = closest(result, val)
    result[index] = val
  end
  result
end