Sha256: c56322ad6d5c1f8609264fc835554c213e5f6feeebe4d070df5495564899415e

Contents?: true

Size: 386 Bytes

Versions: 22

Compression:

Stored size: 386 Bytes

Contents

class Infobar::Trend
  def initialize(values, symbols: %i[ ↘ → ↗ ])
    @values  = values
    @symbols = symbols
    @string  = arrow
  end

  def to_s
    @string
  end

  private

  def arrow
    lr = MoreMath::LinearRegression.new(@values)
    case
    when lr.slope_zero?
      @symbols[1]
    when lr.a > 0
      @symbols[2]
    else
      @symbols[0]
    end.to_s
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
infobar-0.0.3 lib/infobar/trend.rb
infobar-0.0.2 lib/infobar/trend.rb