Class: Bookkeeping::DSL
- Inherits:
-
Object
- Object
- Bookkeeping::DSL
- Defined in:
- lib/bookkeeping/dsl.rb
Instance Attribute Summary collapse
-
#__credits ⇒ Object
readonly
Returns the value of attribute __credits.
-
#__debits ⇒ Object
readonly
Returns the value of attribute __debits.
-
#__description ⇒ Object
readonly
Returns the value of attribute __description.
-
#__reference ⇒ Object
readonly
Returns the value of attribute __reference.
Instance Method Summary collapse
- #build ⇒ Object
- #credit(account, amount) ⇒ Object
- #debit(account, amount) ⇒ Object
- #description(description) ⇒ Object
- #entry ⇒ Object
- #entry=(entry) ⇒ Object
-
#initialize(entry, &block) ⇒ DSL
constructor
A new instance of DSL.
- #transactionable(transactionable) ⇒ Object
Constructor Details
#initialize(entry, &block) ⇒ DSL
Returns a new instance of DSL.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bookkeeping/dsl.rb', line 5 def initialize(entry, &block) @__debits = {} @__credits = {} self.extend Bookkeeping::Proxy self.caller = block.binding.eval "self" @__entry = entry instance_eval &block end |
Instance Attribute Details
#__credits ⇒ Object (readonly)
Returns the value of attribute __credits.
3 4 5 |
# File 'lib/bookkeeping/dsl.rb', line 3 def __credits @__credits end |
#__debits ⇒ Object (readonly)
Returns the value of attribute __debits.
3 4 5 |
# File 'lib/bookkeeping/dsl.rb', line 3 def __debits @__debits end |
#__description ⇒ Object (readonly)
Returns the value of attribute __description.
3 4 5 |
# File 'lib/bookkeeping/dsl.rb', line 3 def __description @__description end |
#__reference ⇒ Object (readonly)
Returns the value of attribute __reference.
3 4 5 |
# File 'lib/bookkeeping/dsl.rb', line 3 def __reference @__reference end |
Instance Method Details
#build ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bookkeeping/dsl.rb', line 43 def build entry.transactionable = @__transactionable || entry.transactionable entry.description = @__description || entry.description __debits.each do |account, amount| entry.debit_amounts.build(account: account, amount: amount) end __credits.each do |account, amount| entry.credit_amounts.build(account: account, amount: amount) end entry end |
#credit(account, amount) ⇒ Object
22 23 24 25 |
# File 'lib/bookkeeping/dsl.rb', line 22 def credit(account, amount) @__credits[account] ||= 0 @__credits[account] += amount end |
#debit(account, amount) ⇒ Object
17 18 19 20 |
# File 'lib/bookkeeping/dsl.rb', line 17 def debit(account, amount) @__debits[account] ||= 0 @__debits[account] += amount end |
#description(description) ⇒ Object
27 28 29 |
# File 'lib/bookkeeping/dsl.rb', line 27 def description(description) @__description = description end |
#entry ⇒ Object
35 36 37 |
# File 'lib/bookkeeping/dsl.rb', line 35 def entry @__entry end |
#entry=(entry) ⇒ Object
39 40 41 |
# File 'lib/bookkeeping/dsl.rb', line 39 def entry=(entry) @__entry = entry end |
#transactionable(transactionable) ⇒ Object
31 32 33 |
# File 'lib/bookkeeping/dsl.rb', line 31 def transactionable(transactionable) @__transactionable = transactionable end |