Skip to content

Instantly share code, notes, and snippets.

@wengzilla
Created December 13, 2012 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wengzilla/e83f221f64077b635047 to your computer and use it in GitHub Desktop.
Save wengzilla/e83f221f64077b635047 to your computer and use it in GitHub Desktop.

Yaml Parsing

Given the a Yaml file of the format found in shipping.yaml parse the file so that we can access it in Ruby.

Your parsing code should return an object that allows you to access attributes using the [] operator:

data["product"].first["sku"] => "BL394D"

The returned object should also allow you to access attributes using method calls:

data.product.first.sku => "BL394D"
invoice: 34843
date : 2001-01-23
billto: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
shipto: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments: >
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment