Class: Reckon::MoneyColumn

Inherits:
Array
  • Object
show all
Defined in:
lib/reckon/money.rb

Instance Method Summary collapse

Constructor Details

#initialize(arr = [], options = {}) ⇒ MoneyColumn

Returns a new instance of MoneyColumn.



87
88
89
# File 'lib/reckon/money.rb', line 87

def initialize(arr = [], options = {})
  arr.each { |str| push(Money.new(str, options)) }
end

Instance Method Details

#merge!(other_column) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/reckon/money.rb', line 98

def merge!(other_column)
  invert = false
  invert = true if positive? && other_column.positive?
  each_with_index do |mon, i|
    other = other_column[i]
    return nil if !mon || !other

    if mon != 0.0 && other == 0.0
      self[i] = -mon if invert
    elsif mon == 0.0 && other != 0.0
      self[i] = other
    else
      self[i] = Money.new(0)
    end
  end
  self
end

#positive?Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
# File 'lib/reckon/money.rb', line 91

def positive?
  each do |money|
    return false if money && money < 0
  end
  true
end