Coder Social home page Coder Social logo

ynab-csv-ruby's Introduction

πŸŽˆπŸ’ΎπŸ’° ynab-ruby πŸ’°πŸ’ΎπŸŽˆ

This is a (WIP) gem for reading data from YNAB CSV exports.

Types of CSVs

When you export a budget from YNAB.com, you get two files:

  • budget.csv, which contains details of monthly, per-category budget goals.
  • register.csv, which contains transactions and their metadata (accounts, budget categories, memos, etc).

Usage

Importing a register

The rows of a YNAB register CSV contain data on every individual transaction in any account/card connected to your YNAB login. The register is read in and parsed into Transaction objects. Outflow and inflow (how much you spent or made) are represented in cents.

[1] pry(main)> r  = Register.new("test/fixtures/register.csv")
=> #<Register:0x007f9ce53bb0a8 @csv_path="test/fixtures/register.csv", @transactions=nil>
[2] pry(main)> r.transactions {|transaction| pp transaction}
=> [#<Transaction:0x007f9ce52abc80
  @account="Checking",
  @category="Groceries",
  @category_group="Mandatory Expenses",
  @category_group_and_category="Mandatory Expenses: Groceries",
  @cleared=true,
  @date=#<Date: 2017-08-01 ((2457967j,0s,0n),+0s,2299161j)>,
  @flag="",
  @inflow=0,
  @memo="Chicken a la king ingredients",
  @outflow=2105,
  @payee="Groceries, Inc.">,
  ...]

Importing a budget

The rows of a YNAB budget CSV contain data on how much money is being allocated and spent per month per category. This gem represents category activity during a month as a CategoryMonth object. Activity/available/budgeted are stored as number of cents. You import a CSV and interact with it as follows:

[1] pry(main)> b = Budget.new("test/fixtures/budget.csv")
=> #<Budget:0x007fdb65806ec8 @category_months=nil, @csv_path="test/fixtures/budget.csv">
[2] pry(main)> b.category_months
=> [#<CategoryMonth:0x007fdb654c6948
  @activity=-7047,
  @available=0,
  @budgeted=7047,
  @category="Cell",
  @category_group="Immediate Obligations",
  @category_group_and_category="Immediate Obligations: Cell",
  @month=#<Date: 2016-12-01 ((2457724j,0s,0n),+0s,2299161j)>>,
  ...]

Local Development

.pryrc includes an import statement, so you can run bundle exec pry to noodle around with the code in console.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.