Class: Ledger::Entry
- Inherits:
-
Object
- Object
- Ledger::Entry
- Defined in:
- lib/libledger/entry.rb
Overview
Declaration for entry object
Class Method Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
- #date ⇒ Object
-
#initialize(params = {}) ⇒ Entry
constructor
A new instance of Entry.
- #name ⇒ Object
- #state ⇒ Object
- #state_as_symbol ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Entry
Returns a new instance of Entry.
10 11 12 |
# File 'lib/libledger/entry.rb', line 10 def initialize(params = {}) @data = params end |
Class Method Details
Instance Method Details
#actions ⇒ Object
40 41 42 |
# File 'lib/libledger/entry.rb', line 40 def actions @actions ||= @data[:actions] end |
#date ⇒ Object
34 35 36 37 38 |
# File 'lib/libledger/entry.rb', line 34 def date return @date if @date @date ||= @data[:date] if @data[:date].is_a? Date @date ||= Date.parse(@data[:date]) end |
#name ⇒ Object
14 15 16 |
# File 'lib/libledger/entry.rb', line 14 def name @name ||= @data[:name] end |
#state ⇒ Object
18 19 20 |
# File 'lib/libledger/entry.rb', line 18 def state @state ||= @data[:state] end |
#state_as_symbol ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/libledger/entry.rb', line 22 def state_as_symbol return @state_as_symbol if @state_as_symbol @state = case state when '*' :cleared when '!' :pending else raise "Unexpected state on #{name}: #{state}" end end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/libledger/entry.rb', line 44 def to_s subject_line + action_lines.join("\n") + "\n" end |