csv_to_sqlite3 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da996b0856a8d3474dfe2bd58b34bc96956874c16cb58281bec0d0fb36f81cf7
4
- data.tar.gz: 92e9180d09351aa8de077b8d6da2f8176a64d2d62123c2c7d5feb93ae0712c4a
3
+ metadata.gz: 29085b03af4098c78b2b1ef115618ea606054866909d4c9f22c8c157336b63fb
4
+ data.tar.gz: e770c2154eb29c5c0cdad8321d2b27b1a9a091d0b96445acc64f962105e39e2b
5
5
  SHA512:
6
- metadata.gz: 82f5f4921be989aec8fdda9dbca21475bfde61295eab6a8c810c53b31f821a76637f8a8970e99d75a32816f9892327bfb1e303df0b3e7ab644981c2be9f33795
7
- data.tar.gz: 926f816917dae6073a2218129fb149c5ea09dd894937babac3b18bcf61dd0f9611e97f4d5004878e17896d881f4e1c92b3cf1afbd9d1199c9f7c351c01b4adb3
6
+ metadata.gz: c7be539d9f72f92e403356d838aeb3837ec5566563af38cd8ca4d87562c484a41d58707e2deb6689348c671d49405eb20bc81067b4b7d5d722c39801cf7021b4
7
+ data.tar.gz: fe1310bc7b61d33d9caa21592fca1f38514dbff276faccc86cf30241e1504683c1956ba0774336a2f3be1755eb1f705b17231b5f2d50dbfc7e390b7601e714e5
Binary file
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.gem
14
14
 
15
15
  *.sqlite3
16
+ examples/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv_to_sqlite3 (0.1.0)
4
+ csv_to_sqlite3 (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -6,17 +6,16 @@
6
6
  # task :default => :spec
7
7
 
8
8
 
9
- require_relative "lib/database"
10
- require_relative "lib/csv_reader"
11
- require_relative "lib/sql/create_table"
12
- require_relative "lib/sql/insert"
9
+ # require_relative "lib/database"
10
+ # require_relative "lib/csv_reader"
11
+ # require_relative "lib/sql/create_table"
12
+ # require_relative "lib/sql/insert"
13
13
 
14
- task default: :setup
14
+ require_relative "lib/csv_to_sqlite"
15
+
16
+ task default: :convert
15
17
 
16
18
  desc "Create tables used in sqlite"
17
- task :setup do
18
- connection = CsvToSQLite::Database.new().connect
19
- csv_table = CsvToSQLite::CsvReader.load_file './spec/test_files/test_file.csv'
20
- CsvToSQLite::SQL::CreateTable.new(name: 'persons', csv_table: csv_table, connection: connection).run
21
- CsvToSQLite::SQL::Insert.new(name: 'persons', csv_table: csv_table, connection: connection).run
19
+ task :convert do
20
+ CsvToSqlite::CsvToSQLite.new.convert(ARGV[1])
22
21
  end
@@ -4,8 +4,20 @@ module CsvToSqlite
4
4
 
5
5
  class CsvReader
6
6
 
7
- def self.load_file file_path
8
- CSV.parse(File.read(file_path), headers: true, col_sep: ';')
7
+ def initialize file_path
8
+ @file_path = file_path
9
+ end
10
+
11
+ def load_file
12
+ CSV.parse(File.read(@file_path), headers: true, col_sep: separator)
13
+ end
14
+
15
+ def separator
16
+ first_line = File.open(@file_path) do |file|
17
+ line = file.readline
18
+ return ";" if line.include? ";"
19
+ return "," if line.include? ","
20
+ end
9
21
  end
10
22
 
11
23
  end
@@ -11,8 +11,7 @@ module CsvToSqlite
11
11
 
12
12
  def convert file_path
13
13
  connection = CsvToSqlite::Database.new().connect
14
- csv_table = CsvToSqlite::CsvReader.load_file file_path
15
- puts file_path
14
+ csv_table = CsvToSqlite::CsvReader.new(file_path).load_file
16
15
  table_name = file_path.split("/").last.split(".csv").first
17
16
  CsvToSqlite::SQL::CreateTable.new(name: table_name, csv_table: csv_table, connection: connection).run
18
17
  CsvToSqlite::SQL::Insert.new(name: table_name, csv_table: csv_table, connection: connection).run
@@ -1,3 +1,3 @@
1
1
  module CsvToSqlite
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -8,7 +8,9 @@ module CsvToSqlite::SQL
8
8
 
9
9
  def sql_for column
10
10
  @data = @csv_table[column][0..2]
11
- if int?
11
+ if null?
12
+ type = "TEXT DEFAULT NULL"
13
+ elsif int?
12
14
  type = "INTEGER"
13
15
  elsif float?
14
16
  type = "FLOAT"
@@ -24,6 +26,11 @@ module CsvToSqlite::SQL
24
26
  "#{column} #{type},"
25
27
  end
26
28
 
29
+ def null?
30
+ match_cases = @data.map { |value| value == nil }
31
+ match_cases.any? { |value| value == true }
32
+ end
33
+
27
34
  def int?
28
35
  meta_comparing :Integer
29
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_to_sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaofelipelopes
@@ -18,6 +18,7 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".DS_Store"
21
22
  - ".gitignore"
22
23
  - ".rspec"
23
24
  - ".travis.yml"