Class: CSVR::App
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #create(db, table) ⇒ Object
- #format ⇒ Object
-
#initialize(file) ⇒ App
constructor
A new instance of App.
- #parse ⇒ Object
Methods included from Format
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
19 20 21 |
# File 'lib/csvr.rb', line 19 def file @file end |
#filters ⇒ Object
Returns the value of attribute filters.
20 21 22 |
# File 'lib/csvr.rb', line 20 def filters @filters end |
#headers ⇒ Object
Returns the value of attribute headers.
20 21 22 |
# File 'lib/csvr.rb', line 20 def headers @headers end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
19 20 21 |
# File 'lib/csvr.rb', line 19 def rows @rows end |
#types ⇒ Object (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 |
#format ⇒ Object
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 |
#parse ⇒ Object
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 |