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.



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

def initialize( v, w=nil) @v, @w = v, w || 10 end

Instance Attribute Details

#vObject (readonly)

Returns the value of attribute v.



110
111
112
# File 'lib/pve/helper.rb', line 110

def v
  @v
end

#wObject (readonly)

Returns the value of attribute w.



110
111
112
# File 'lib/pve/helper.rb', line 110

def w
  @w
end

Instance Method Details

#inspectObject



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

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

#lengthObject



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

def length() @w end

#to_sObject



115
116
117
118
119
120
121
122
# File 'lib/pve/helper.rb', line 115

def to_s
  #y = w - (v*w).round
  y = (v*w).round
  x = (100*v).round
  r = "%*s" % [w, 0==x ? '·' : x]
  #"\e[0m#{r[0...y]}\e[1;4;#{0.75>v ? 32 : 31}m#{r[y..-1]}\e[0m"
  "\e[1;4;#{0.75>v ? 32 : 31}m#{r[0...y]}\e[0m#{r[y..-1]}"
end