Class: RBench::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/rbench/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, name, options = {}) ⇒ Column

Returns a new instance of Column.



5
6
7
8
9
10
11
12
# File 'lib/rbench/column.rb', line 5

def initialize(runner, name, options = {})
  @runner  = runner
  @name    = name
  @title   = options[:title] || (@name == :times ? "" : @name.to_s.upcase)
  @width   = options[:width] || [@title.length,7].max
  @compare = options[:compare]
  @default = @compare ? @compare : options[:default]
end

Instance Attribute Details

#compareObject

Returns the value of attribute compare.



3
4
5
# File 'lib/rbench/column.rb', line 3

def compare
  @compare
end

#defaultObject

Returns the value of attribute default.



3
4
5
# File 'lib/rbench/column.rb', line 3

def default
  @default
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rbench/column.rb', line 3

def name
  @name
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/rbench/column.rb', line 3

def title
  @title
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/rbench/column.rb', line 3

def width
  @width
end

Instance Method Details

#to_s(val = title) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rbench/column.rb', line 14

def to_s(val=title)
  str = case val
    when Array      then "%#{width-1}.2f" % (val[0] / val[1]) + "x"
    when Float      then "%#{width}.3f" % val
    when Integer    then "%#{width}.0f" % val
    when TrueClass  then " "*(width/2.0).floor + "X" + " "*(width/2.0).floor
    when String     then "%#{width}s" % (val)[0,width]
    when Object     then " " * width
  end
  return " #{(str.to_s+" "*width)[0,width]} |"
end