Class: Owemegod::ExpenseCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/owemegod/expense_collection.rb

Instance Method Summary collapse

Instance Method Details

#add_expense(name, value) ⇒ Object



11
12
13
# File 'lib/owemegod/expense_collection.rb', line 11

def add_expense(name, value)
  expenses << Expense.new(name: name, value: value)
end

#each(&block) ⇒ Object



19
20
21
22
23
# File 'lib/owemegod/expense_collection.rb', line 19

def each(&block)
  expenses.each do |expense|
    block.call expense
  end
end

#expensesObject



7
8
9
# File 'lib/owemegod/expense_collection.rb', line 7

def expenses
  @expenses ||= []
end

#valueObject



15
16
17
# File 'lib/owemegod/expense_collection.rb', line 15

def value
  inject(0){|sum, expense|  sum + expense.value}
end