Class: RBench::Column
- Inherits:
-
Object
- Object
- RBench::Column
- Defined in:
- lib/rbench/column.rb
Instance Attribute Summary collapse
-
#compare ⇒ Object
Returns the value of attribute compare.
-
#default ⇒ Object
Returns the value of attribute default.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(runner, name, options = {}) ⇒ Column
constructor
A new instance of Column.
- #to_s(val = title) ⇒ Object
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, = {}) @runner = runner @name = name @title = [:title] || (@name == :times ? "" : @name.to_s.upcase) @width = [:width] || [@title.length,7].max @compare = [:compare] @default = @compare ? @compare : [:default] end |
Instance Attribute Details
#compare ⇒ Object
Returns the value of attribute compare.
3 4 5 |
# File 'lib/rbench/column.rb', line 3 def compare @compare end |
#default ⇒ Object
Returns the value of attribute default.
3 4 5 |
# File 'lib/rbench/column.rb', line 3 def default @default end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rbench/column.rb', line 3 def name @name end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/rbench/column.rb', line 3 def title @title end |
#width ⇒ Object
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 |