Class: CSVR::App

Inherits:
Object
  • Object
show all
Includes:
Parse, Format
Defined in:
lib/csvr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Format

headers, row, type

Methods included from Parse

filter, headers, index, rows, type

Constructor Details

#initialize(file) ⇒ App

Returns a new instance of App.



22
23
24
# File 'lib/csvr.rb', line 22

def initialize(file)
	@file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



19
20
21
# File 'lib/csvr.rb', line 19

def file
  @file
end

#filtersObject

Returns the value of attribute filters.



20
21
22
# File 'lib/csvr.rb', line 20

def filters
  @filters
end

#headersObject

Returns the value of attribute headers.



20
21
22
# File 'lib/csvr.rb', line 20

def headers
  @headers
end

#rowsObject (readonly)

Returns the value of attribute rows.



19
20
21
# File 'lib/csvr.rb', line 19

def rows
  @rows
end

#typesObject (readonly)

Returns the value of attribute types.



19
20
21
# File 'lib/csvr.rb', line 19

def types
  @types
end

Instance Method Details

#create(db, table) ⇒ Object



39
40
41
42
43
44
# File 'lib/csvr.rb', line 39

def create(db, table)
	self.parse
	self.format
	db = Database.new(db, table, @headers, @rows)
	db.create
end

#formatObject



34
35
36
37
# File 'lib/csvr.rb', line 34

def format
	@headers = Format.headers(@headers, @types) unless @types.nil?
	@rows = @rows.map{ |row| Format.row(row) }
end

#parseObject



26
27
28
29
30
31
32
# File 'lib/csvr.rb', line 26

def parse
	@headers ||= CSVR::Parse.headers(@file)
	@rows = CSVR::Parse.rows(@file, @headers, @filters)
	puts "HEADERS: #{@headers}, #{@headers.class}"
	puts "ROWS: #{@rows.sample}, #{@rows.sample.class}, #{@rows.class}, #{@rows.empty?}"
	@types = CSVR::Parse.type(@headers, @rows[0]) unless @rows.empty?
end