Sha256: bc4dedd27c6b1f6b9cbdc86b87296423ad4e03668be9d73ea0a2d88518b64eed

Contents?: true

Size: 548 Bytes

Versions: 4

Compression:

Stored size: 548 Bytes

Contents

class Infobar::Number
  def initialize(value, format: nil, unit: nil, prefix: 1000, separate: nil)
    duration = Tins::Duration.new(value)
    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

  def to_s
    @string
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infobar-0.6.1 lib/infobar/number.rb
infobar-0.6.0 lib/infobar/number.rb
infobar-0.5.1 lib/infobar/number.rb
infobar-0.5.0 lib/infobar/number.rb