https://github.com/ralfebert/ledgerjournal
ledgerjournal is a Ruby gem to read and write ledger accounting files.
https://github.com/ralfebert/ledgerjournal
accounting ledger-cli ruby-gem
Last synced: 12 months ago
JSON representation
ledgerjournal is a Ruby gem to read and write ledger accounting files.
- Host: GitHub
- URL: https://github.com/ralfebert/ledgerjournal
- Owner: ralfebert
- License: mit
- Created: 2020-04-26T09:21:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-29T15:33:56.000Z (over 4 years ago)
- Last Synced: 2025-02-17T16:17:54.869Z (about 1 year ago)
- Topics: accounting, ledger-cli, ruby-gem
- Language: Ruby
- Homepage:
- Size: 43.9 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ledgerjournal
[](https://badge.fury.io/rb/ledgerjournal)
[](https://travis-ci.org/github/ralfebert/ledgerjournal)
[](https://www.rubydoc.info/gems/ledgerjournal/)
ledgerjournal is a Ruby gem to read and write [ledger](https://www.ledger-cli.org/) accounting files.
For parsing, it uses the [ledger xml command](https://www.ledger-cli.org/3.0/doc/ledger3.html#The-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:
```ruby
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:
```ruby
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:
```ruby
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:
```ruby
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:
```ruby
Ledger.defaults = Options.new(date_format: '%d.%m.%Y', decimal_comma: true)
```
or:
```ruby
Ledger.defaults = Ledger::Options.for_locale(:de)
```
## Installation
Add this line to your application's Gemfile:
```ruby
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.