class CsvPack::Pack
Public Class Methods
new( path )
click to toggle source
load (tabular) datapackage into memory
# File lib/csvpack/pack.rb, line 51 def initialize( path ) ## convenience ## - check: if path is a folder/directory ## (auto-)add /datapackage.json @meta = Meta.load_file( path ) pack_dir = File.dirname(path) pp @meta ## read in tables @tables = [] @meta.resources.each do |r| ## build table data @tables << build_tab( r, pack_dir ) end ## pp @tables end
Public Instance Methods
build_tab( h, pack_dir )
click to toggle source
# File lib/csvpack/pack.rb, line 80 def build_tab( h, pack_dir ) name = h['name'] relative_path = h['path'] if relative_path.nil? relative_path = "#{name}.csv" puts " warn: no path defined; using fallback '#{relative_path}'" end puts " reading resource (table) #{name} (#{relative_path})..." pp h path = "#{pack_dir}/#{relative_path}" text = File.open( path, 'r:utf-8' ).read tab = Tab.new( h, text ) tab end
meta()
click to toggle source
# File lib/csvpack/pack.rb, line 73 def meta() @meta; end
table()
click to toggle source
convenience method - return first table
# File lib/csvpack/pack.rb, line 78 def table() @tables[0]; end
tables()
click to toggle source
# File lib/csvpack/pack.rb, line 76 def tables() @tables; end