Class: Rledger::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/rledger/ledger/post.rb

Overview

Entry contains the specification of an operation on an account

Entries are the basis for Transactions.

We allow for operations with no amount, in which case the amount is computed from remaining entries in the Transaction (see the class Transaction)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePost

Returns a new instance of Post.



15
16
17
18
19
# File 'lib/rledger/ledger/post.rb', line 15

def initialize
  @voice = ""
  @amount = Amount.new
  @comment = ""
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



13
14
15
# File 'lib/rledger/ledger/post.rb', line 13

def amount
  @amount
end

#commentObject

Returns the value of attribute comment.



13
14
15
# File 'lib/rledger/ledger/post.rb', line 13

def comment
  @comment
end

#voiceObject

Returns the value of attribute voice.



13
14
15
# File 'lib/rledger/ledger/post.rb', line 13

def voice
  @voice
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rledger/ledger/post.rb', line 41

def derived?
  @derived
end

#parse(s) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rledger/ledger/post.rb', line 21

def parse(s)
  voice = "([a-zA-Z:-_!@']+)"
  amount = "([^;]*|)"  # a regexp which allows to move to the next token
  comment = ";? ?(.*|)"
  b = "[\t ]+"
  ob = "[\t ]*"
  
  match = Regexp.new(b + voice + ob + amount + ob + comment).match(s)

  if match
    @voice = match[1]
    @amount.parse(match[2])
    @derived = match[2] == ""
    @comment = match[3]
    true
  else
    false
  end
end

#to_sObject



45
46
47
# File 'lib/rledger/ledger/post.rb', line 45

def to_s
  "\t#{@voice}#{amount_to_s}\t#{comment_to_s}\n"
end