class BridgeBlueprint::DataDump
Public Class Methods
new(path)
click to toggle source
# File lib/bridge_blueprint/data_dump.rb, line 10 def initialize(path) @path = path raise "File not found #{path}" unless File.exist?(path) end
Public Instance Methods
each_row(name) { |row| ... }
click to toggle source
# File lib/bridge_blueprint/data_dump.rb, line 15 def each_row(name) extract_from_zip("#{name}.csv") do |file| CSV.foreach(file, headers: true) do |row| yield(row) end end end
Private Instance Methods
extract_from_zip(name) { |"#{dir}/#{name}"| ... }
click to toggle source
# File lib/bridge_blueprint/data_dump.rb, line 25 def extract_from_zip(name) Dir.mktmpdir do |dir| path = nil file = nil Zip::File.open(@path) do |zip_file| zip_file.each do |entry| next unless name.to_s == entry.name path = "#{dir}/#{entry.name}" file = entry.extract(path) break end end if file yield "#{dir}/#{name}" if block_given? else raise "File #{name} not found in zip archive #{@path}" end end end