Class: Statements::Search
- Inherits:
-
Object
- Object
- Statements::Search
- Defined in:
- lib/statements/search.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #credits ⇒ Object
- #debits ⇒ Object
-
#initialize(input) ⇒ Search
constructor
A new instance of Search.
- #total(collection = :transactions) ⇒ Object
- #transactions ⇒ Object
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
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/statements/search.rb', line 6 def input @input end |
Instance Method Details
#credits ⇒ Object
20 21 22 |
# File 'lib/statements/search.rb', line 20 def credits transactions.select { |t| t.amount > 0 } end |
#debits ⇒ Object
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 |
#transactions ⇒ Object
12 13 14 |
# File 'lib/statements/search.rb', line 12 def transactions @transactions ||= query.all end |