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.



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

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

Instance Method Details

#merge!(other_column) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/reckon/money.rb', line 105

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)


98
99
100
101
102
103
# File 'lib/reckon/money.rb', line 98

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