Class: Ambito::Variation

Inherits:
Object
  • Object
show all
Defined in:
lib/ambito/variation.rb

Constant Summary collapse

{up: "📈", down: "📉", equal: "📊"}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Variation

Returns a new instance of Variation.



7
8
9
# File 'lib/ambito/variation.rb', line 7

def initialize(value)
  @value = parse(value)
end

Instance Attribute Details

#value ⇒ Object (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/ambito/variation.rb', line 5

def value
  @value
end

Class Method Details

.[](value) ⇒ Object



32
33
34
# File 'lib/ambito/variation.rb', line 32

def [](value)
  new(value)
end

Instance Method Details

#to_s ⇒ Object



11
12
13
# File 'lib/ambito/variation.rb', line 11

def to_s
  sprintf("%.2f" % value) << "%"
end

#trend ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ambito/variation.rb', line 15

def trend
  if value.positive?
    TRENDS[:up]
  elsif value.negative?
    TRENDS[:down]
  else
    TRENDS[:equal]
  end
end