Class: Ledger::Entry
- Inherits:
-
Object
- Object
- Ledger::Entry
- Includes:
- Comparable
- Defined in:
- lib/libledger/entry.rb
Overview
Declaration for entry object
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #actions ⇒ Object
- #date ⇒ Object
-
#initialize(params = {}) ⇒ Entry
constructor
A new instance of Entry.
- #name ⇒ Object
- #state ⇒ Object
- #state_str ⇒ Object
- #state_sym ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Entry
Returns a new instance of Entry.
17 18 19 |
# File 'lib/libledger/entry.rb', line 17 def initialize(params = {}) @data = params end |
Class Method Details
.from_lines(lines) ⇒ Object
76 77 78 79 80 |
# File 'lib/libledger/entry.rb', line 76 def from_lines(lines) params = parse_first_line(lines.shift) params[:actions] = lines.map { |x| parse_action_line x } Entry.new(params) end |
Instance Method Details
#<=>(other) ⇒ Object
51 52 53 54 |
# File 'lib/libledger/entry.rb', line 51 def <=>(other) return nil unless other.is_a? Ledger::Entry date <=> other.date end |
#actions ⇒ Object
43 44 45 |
# File 'lib/libledger/entry.rb', line 43 def actions @actions ||= @data[:actions] end |
#date ⇒ Object
37 38 39 40 41 |
# File 'lib/libledger/entry.rb', line 37 def date return @date if @date @date ||= @data[:date] if @data[:date].is_a? Date @date ||= Date.parse(@data[:date]) end |
#name ⇒ Object
21 22 23 |
# File 'lib/libledger/entry.rb', line 21 def name @name ||= @data[:name] end |
#state ⇒ Object
25 26 27 |
# File 'lib/libledger/entry.rb', line 25 def state @state ||= @data[:state] end |
#state_str ⇒ Object
33 34 35 |
# File 'lib/libledger/entry.rb', line 33 def state_str @state_str ||= state.is_a?(Symbol) ? STATE_MAPPING[state] : state end |
#state_sym ⇒ Object
29 30 31 |
# File 'lib/libledger/entry.rb', line 29 def state_sym @state_sym ||= state.is_a?(Symbol) ? state : STATE_MAPPING.invert[state] end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/libledger/entry.rb', line 47 def to_s subject_line + action_lines.join("\n") + "\n" end |