Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created May 29, 2014 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashaw/243ea844aa8d77af7152 to your computer and use it in GitHub Desktop.
Save ashaw/243ea844aa8d77af7152 to your computer and use it in GitHub Desktop.
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