Class: Inscriber::Downloader

Inherits:
Object
  • Object
show all
Includes:
TableHelpers
Defined in:
lib/inscriber/downloader.rb

Instance Method Summary collapse

Methods included from TableHelpers

#original_column_name, #original_table_name

Constructor Details

#initialize(database) ⇒ Downloader

Returns a new instance of Downloader.



5
6
7
8
9
# File 'lib/inscriber/downloader.rb', line 5

def initialize(database)
  @db          ||= connect_to_db(database)
  @database    = database
  @result_hash = Hash.new(0)
end

Instance Method Details

#downloadObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inscriber/downloader.rb', line 11

def download
  @database.tables.each do |table|
    record_hash = Hash.new(0)
    records = records_from_table(table[:name]).all
    unless records.empty?
      records.each do |record|
        record_hash[record[original_column_name(table[:name])]] = generate_hash_from_record(record, table)
      end
      @result_hash[table[:name]] = record_hash
    end
  end
  @result_hash
end