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.



85
86
87
# File 'lib/reckon/money.rb', line 85

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

Instance Method Details

#merge!(other_column) ⇒ Object



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

def merge!( other_column )
  invert = false
  invert = true if self.positive? && other_column.positive?
  self.each_with_index do |mon, i|
    other = other_column[i]
    return nil if (!mon || !other)
    if mon != 0.00 && other == 0.0
      if invert
        self[i]= -mon
      end
    elsif mon == 0.00 && other != 0.00
      self[i] = other
    else
      return nil
    end
  end
  self
end

#positive?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/reckon/money.rb', line 89

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