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.



96
97
98
# File 'lib/reckon/money.rb', line 96

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

Instance Method Details

#merge!(other_column) ⇒ Object



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

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)


100
101
102
103
104
105
# File 'lib/reckon/money.rb', line 100

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