Class: Ledger::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/libledger/entry.rb

Overview

Declaration for entry object

Class Method Summary collapse

Instance Method Summary collapse

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

.from_lines(lines) ⇒ Object



68
69
70
71
72
# File 'lib/libledger/entry.rb', line 68

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

#actionsObject



40
41
42
# File 'lib/libledger/entry.rb', line 40

def actions
  @actions ||= @data[:actions]
end

#dateObject



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

#nameObject



14
15
16
# File 'lib/libledger/entry.rb', line 14

def name
  @name ||= @data[:name]
end

#stateObject



18
19
20
# File 'lib/libledger/entry.rb', line 18

def state
  @state ||= @data[:state]
end

#state_as_symbolObject



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_sObject



44
45
46
# File 'lib/libledger/entry.rb', line 44

def to_s
  subject_line + action_lines.join("\n") + "\n"
end