class Ledger::Journal

Declaration for list of entries

Attributes

entries[R]

Public Class Methods

from_file(file) click to toggle source
# File lib/libledger/journal.rb, line 22
def from_file(file)
  from_text(File.read(file))
end
from_files(files) click to toggle source
# File lib/libledger/journal.rb, line 16
def from_files(files)
  Journal.new(
    entries: files.map { |x| from_file(x).entries }.flatten
  )
end
from_text(text) click to toggle source
# File lib/libledger/journal.rb, line 26
def from_text(text)
  Journal.new(entries: text_to_entries(text))
end
new(params = {}) click to toggle source
# File lib/libledger/journal.rb, line 7
def initialize(params = {})
  @entries = params[:entries] || []
end

Private Class Methods

text_to_entries(text) click to toggle source
# File lib/libledger/journal.rb, line 32
def text_to_entries(text)
  text.split(/\n\n+/).map do |x|
    x.strip!
    next if x.start_with? ';'

    Entry.from_lines(x.split("\n"))
  end.compact
end

Public Instance Methods

to_s() click to toggle source
# File lib/libledger/journal.rb, line 11
def to_s
  @entries.sort.map(&:to_s).join("\n")
end