mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Add Money and Money Series (#505)
* Add Money class * Standardize creation of money series * Formatting * Fix test
This commit is contained in:
parent
89ea12e9a1
commit
0fe9b6d34a
16 changed files with 228 additions and 161 deletions
|
@ -1,26 +1,27 @@
|
|||
class Trend
|
||||
attr_reader :current, :previous
|
||||
attr_reader :current, :previous, :type
|
||||
|
||||
def initialize(current, previous)
|
||||
@current = current
|
||||
@previous = previous
|
||||
end
|
||||
def initialize(current:, previous: nil, type: :asset)
|
||||
@current = current
|
||||
@previous = previous
|
||||
@type = type # :asset means positive trend is good, :liability means negative trend is good
|
||||
end
|
||||
|
||||
def direction
|
||||
return "flat" unless @previous
|
||||
return "up" if @current > @previous
|
||||
return "down" if @current < @previous
|
||||
"flat"
|
||||
end
|
||||
def direction
|
||||
return "flat" unless @previous
|
||||
return "up" if @current > @previous
|
||||
return "down" if @current < @previous
|
||||
"flat"
|
||||
end
|
||||
|
||||
def amount
|
||||
return 0 if @previous.nil?
|
||||
@current - @previous
|
||||
end
|
||||
def amount
|
||||
return 0 if @previous.nil?
|
||||
@current - @previous
|
||||
end
|
||||
|
||||
def percent
|
||||
return 0 if @previous.nil?
|
||||
return Float::INFINITY if @previous == 0
|
||||
((@current - @previous).abs / @previous.to_f * 100).round(1)
|
||||
end
|
||||
def percent
|
||||
return 0 if @previous.nil?
|
||||
return Float::INFINITY if @previous == 0
|
||||
((@current - @previous).abs / @previous.to_f * 100).round(1)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue