Class: Infobar::Number
Instance Method Summary collapse
-
#initialize(value, format: nil, unit: nil, prefix: 1000, separate: nil) ⇒ Number
constructor
A new instance of Number.
- #to_s ⇒ Object
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_s ⇒ Object
17 18 19 |
# File 'lib/infobar/number.rb', line 17 def to_s @string end |