Sha256: c95418c4ad8e60c303a5adc49c42840fb53abc5b804efd5df12cef5655ee1494

Contents?: true

Size: 608 Bytes

Versions: 19

Compression:

Stored size: 608 Bytes

Contents

require 'infobar/trend'

class Infobar::Rate
  def initialize(value, fifo_values = [], **opts)
    opts[:format] ||= '%.3f%U%t'
    opts[:format] = add_trend(opts[:format], fifo_values)
    @string = value.full? do
      if opts[:format].include?('%U')
        Tins::Unit.format(value, **opts)
      else
        opts[:format] % value
      end
    end.to_s
  end

  def to_s
    @string
  end

  private

  def add_trend(format, fifo_values)
    if fifo_values.empty?
      format.gsub('%t', ?⤿)
    else
      trend = Infobar::Trend.new(fifo_values)
      format.gsub('%t', trend.to_s)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
infobar-0.8.1 lib/infobar/rate.rb
infobar-0.8.0 lib/infobar/rate.rb
infobar-0.7.4 lib/infobar/rate.rb
infobar-0.7.2 lib/infobar/rate.rb
infobar-0.7.1 lib/infobar/rate.rb
infobar-0.7.0 lib/infobar/rate.rb
infobar-0.6.2 lib/infobar/rate.rb
infobar-0.6.1 lib/infobar/rate.rb
infobar-0.6.0 lib/infobar/rate.rb
infobar-0.5.1 lib/infobar/rate.rb
infobar-0.5.0 lib/infobar/rate.rb
infobar-0.4.0 lib/infobar/rate.rb
infobar-0.3.0 lib/infobar/rate.rb
infobar-0.2.0 lib/infobar/rate.rb
infobar-0.1.1 lib/infobar/rate.rb
infobar-0.1.0 lib/infobar/rate.rb
infobar-0.0.7 lib/infobar/rate.rb
infobar-0.0.6 lib/infobar/rate.rb
infobar-0.0.5 lib/infobar/rate.rb