Created
May 29, 2014 15:14
-
-
Save ashaw/243ea844aa8d77af7152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RDB | |
attr_reader :headers, :data | |
def initialize(f) | |
@file = File.open(f).readlines | |
@data = @file.reject {|q| q =~ /^#/ } | |
@headers = @data.shift.chomp.split("\t") | |
@data.shift # remove schema line | |
@data.map! {|q| q.chomp.split("\t")} | |
end | |
def row_hash(idx) | |
Hash[@headers.zip(@data[idx])] | |
end | |
def [](idx) | |
row_hash(idx) | |
end | |
def each | |
0.upto(@data.length - 1).each do |idx| | |
yield row_hash(idx) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment