0.0
No release in over 3 years
Low commit activity in last 3 years
ledgerjournal is a Ruby gem to read and write ledger accounting files. For parsing, it uses the xml output from ledger. For outputting, it formats the ledger data to String in custom Ruby code. The ledger binary needs to be installed to parse and pretty-print.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 1.10
~> 1.3
 Project Readme

ledgerjournal

Gem Version Build Status Yard Docs

ledgerjournal is a Ruby gem to read and write ledger accounting files. For parsing, it uses the ledger xml command. For outputting, it formats the ledger data as String in Ruby. The ledger binary needs to be installed to parse and pretty-print.

Usage

Parsing a ledger journal file:

journal = Ledger::Journal.new(path: "example_journal.dat")
journal.transactions.each do |tx|
  puts tx.date, tx.payee
end

Creating a ledger file from scratch:

journal = Ledger::Journal.new()

journal.transactions << Ledger::Transaction.new(
  date: Date.new(2020, 1, 2),
  payee: 'Example Payee',
  metadata: { "Foo" => "Bar", "Description" => "Example Transaction" },
  postings: [
    Ledger::Posting.new(account: "Expenses:Unknown", currency: "EUR", amount: BigDecimal('1234.56'), metadata: { "Foo" => "Bar", "Description" => "Example Posting" }),
    Ledger::Posting.new(account: "Assets:Checking", currency: "EUR", amount: BigDecimal('-1234.56'))
  ]
)

puts(journal.to_s)

Appending to a ledger journal:

journal = Ledger::Journal.new(path: "example_journal.dat")
journal.transactions << Ledger::Transaction.new(
  date: Date.new(2020, 1, 2),
  payee: 'Example Payee',
  postings: [
    Ledger::Posting.new(account: "Expenses:Unknown", currency: "EUR", amount: BigDecimal('1234.56')),
    Ledger::Posting.new(account: "Assets:Checking", currency: "EUR", amount: BigDecimal('-1234.56'))
  ]
)
journal.save!

Running ledger commands:

puts Ledger.defaults.run('--version')

Locale-specific settings

By default ledgerjournal expects the date format '%Y/%m/%d' and amounts with decimal point (1234.56). This is configurable:

Ledger.defaults = Options.new(date_format: '%d.%m.%Y', decimal_comma: true)

or:

Ledger.defaults = Ledger::Options.for_locale(:de)

Installation

Add this line to your application's Gemfile:

gem 'ledgerjournal'

Or install it yourself as:

$ gem install ledgerjournal

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ralfebert/ledgerjournal.

License

ledgerjournal is released under the MIT License. See LICENSE.md.