Class: Infobar::Number

Inherits:
Object show all
Defined in:
lib/infobar/number.rb

Instance Method Summary collapse

Constructor Details

#initialize(value, format: nil, unit: nil, prefix: 1000, separate: nil) ⇒ Number

Returns a new instance of Number.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/infobar/number.rb', line 2

def initialize(value, format: nil, unit: nil, prefix: 1000, separate: nil)
  case format
  when /%U/
    unit   ||= 'i/s'
    prefix ||= 1000
    @string = Tins::Unit.format(value, format: format, unit: unit, prefix: prefix)
  else
    format ||= '%f'
    @string = format ? format % value : value.to_s
    if Integer === value && separate
      @string.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{separate}")
    end
  end
end

Instance Method Details

#to_sObject



17
18
19
# File 'lib/infobar/number.rb', line 17

def to_s
  @string
end