Class: TablizedOutput::Percentage
Instance Attribute Summary collapse
-
#v ⇒ Object
readonly
Returns the value of attribute v.
-
#w ⇒ Object
readonly
Returns the value of attribute w.
Instance Method Summary collapse
-
#initialize(v, w = nil) ⇒ Percentage
constructor
A new instance of Percentage.
- #inspect ⇒ Object
- #length ⇒ Object
- #to_s ⇒ Object
Methods inherited from B
Constructor Details
#initialize(v, w = nil) ⇒ Percentage
Returns a new instance of Percentage.
123 |
# File 'lib/pve/helper.rb', line 123 def initialize( v, w=nil) @v, @w = v, w || 10 end |
Instance Attribute Details
#v ⇒ Object (readonly)
Returns the value of attribute v.
122 123 124 |
# File 'lib/pve/helper.rb', line 122 def v @v end |
#w ⇒ Object (readonly)
Returns the value of attribute w.
122 123 124 |
# File 'lib/pve/helper.rb', line 122 def w @w end |
Instance Method Details
#inspect ⇒ Object
125 |
# File 'lib/pve/helper.rb', line 125 def inspect() "#<TO:Percentage #{@v}%>" end |
#length ⇒ Object
124 |
# File 'lib/pve/helper.rb', line 124 def length() @w end |
#to_s ⇒ Object
127 128 129 130 131 132 |
# File 'lib/pve/helper.rb', line 127 def to_s y = (v*w).round x = (100*v).round r = "%*s" % [w, 0==x ? 'ยท' : x] "\e[1;4;#{0.75>v ? 32 : 31}m#{r[0...y]}\e[0m#{r[y..-1]}" end |