class Rledger::Post

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)

Attributes

amount[RW]
comment[RW]
voice[RW]

Public Class Methods

new() click to toggle source
# File lib/rledger/ledger/post.rb, line 15
def initialize
  @voice = ""
  @amount = Amount.new
  @comment = ""
end

Public Instance Methods

derived?() click to toggle source
# File lib/rledger/ledger/post.rb, line 41
def derived?
  @derived
end
parse(s) click to toggle source
# 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_s() click to toggle source
# File lib/rledger/ledger/post.rb, line 45
def to_s
  "\t#{@voice}#{amount_to_s}\t#{comment_to_s}\n"
end

Private Instance Methods

amount_to_s() click to toggle source
# File lib/rledger/ledger/post.rb, line 51
def amount_to_s
  derived? ? "" : "\t#{@amount.to_s}"
end
comment_to_s() click to toggle source
# File lib/rledger/ledger/post.rb, line 55
def comment_to_s
  @comment == "" ? "" : "; #{@comment}"
end