Class: Bookkeeping::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/bookkeeping/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#__creditsObject (readonly)

Returns the value of attribute __credits.



3
4
5
# File 'lib/bookkeeping/dsl.rb', line 3

def __credits
  @__credits
end

#__debitsObject (readonly)

Returns the value of attribute __debits.



3
4
5
# File 'lib/bookkeeping/dsl.rb', line 3

def __debits
  @__debits
end

#__descriptionObject (readonly)

Returns the value of attribute __description.



3
4
5
# File 'lib/bookkeeping/dsl.rb', line 3

def __description
  @__description
end

#__referenceObject (readonly)

Returns the value of attribute __reference.



3
4
5
# File 'lib/bookkeeping/dsl.rb', line 3

def __reference
  @__reference
end

Instance Method Details

#buildObject



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 |, amount|
    entry.debit_amounts.build(account: , amount: amount)
  end

  __credits.each do |, amount|
    entry.credit_amounts.build(account: , amount: amount)
  end

  entry
end

#credit(account, amount) ⇒ Object



22
23
24
25
# File 'lib/bookkeeping/dsl.rb', line 22

def credit(, amount)
  @__credits[] ||= 0
  @__credits[] += amount
end

#debit(account, amount) ⇒ Object



17
18
19
20
# File 'lib/bookkeeping/dsl.rb', line 17

def debit(, amount)
  @__debits[] ||= 0
  @__debits[] += amount
end

#description(description) ⇒ Object



27
28
29
# File 'lib/bookkeeping/dsl.rb', line 27

def description(description)
  @__description = description
end

#entryObject



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