Class: Statements::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/statements/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Search

Returns a new instance of Search.



8
9
10
# File 'lib/statements/search.rb', line 8

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/statements/search.rb', line 6

def input
  @input
end

Instance Method Details

#creditsObject



20
21
22
# File 'lib/statements/search.rb', line 20

def credits
  transactions.select { |t| t.amount > 0 }
end

#debitsObject



16
17
18
# File 'lib/statements/search.rb', line 16

def debits
  transactions.select { |t| t.amount < 0 }
end

#total(collection = :transactions) ⇒ Object



24
25
26
# File 'lib/statements/search.rb', line 24

def total(collection = :transactions)
  __send__(collection).inject(0) { |sum, t| sum + t.amount }
end

#transactionsObject



12
13
14
# File 'lib/statements/search.rb', line 12

def transactions
  @transactions ||= query.all
end