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

Methods included from Parse

filter, headers, index, maximum, rows

Constructor Details

#initialize(file) ⇒ 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

Instance Method Details

#create(db, table) ⇒ Object



36
37
38
39
40
41
# File 'lib/csvr.rb', line 36

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

#formatObject



31
32
33
34
# File 'lib/csvr.rb', line 31

def format
  @headers = Format.headers(@headers)
  @rows = @rows.map{ |row| Format.row(row) }
end

#parseObject



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

def parse
  @headers ||= CSVR::Parse.headers(@file)
  @rows = CSVR::Parse.rows(@file, @headers, @filters)
end