Class: Rledger::Post
- Inherits:
-
Object
- Object
- Rledger::Post
- 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
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#voice ⇒ Object
Returns the value of attribute voice.
Instance Method Summary collapse
- #derived? ⇒ Boolean
-
#initialize ⇒ Post
constructor
A new instance of Post.
- #parse(s) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Post
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
#amount ⇒ Object
Returns the value of attribute amount.
13 14 15 |
# File 'lib/rledger/ledger/post.rb', line 13 def amount @amount end |
#comment ⇒ Object
Returns the value of attribute comment.
13 14 15 |
# File 'lib/rledger/ledger/post.rb', line 13 def comment @comment end |
#voice ⇒ Object
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
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_s ⇒ Object
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 |