Class: TablizedOutput::Percentage

Inherits:
B
  • Object
show all
Defined in:
lib/pve/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#vObject (readonly)

Returns the value of attribute v.



122
123
124
# File 'lib/pve/helper.rb', line 122

def v
  @v
end

#wObject (readonly)

Returns the value of attribute w.



122
123
124
# File 'lib/pve/helper.rb', line 122

def w
  @w
end

Instance Method Details

#inspectObject



125
# File 'lib/pve/helper.rb', line 125

def inspect() "#<TO:Percentage #{@v}%>" end

#lengthObject



124
# File 'lib/pve/helper.rb', line 124

def length() @w end

#to_sObject



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