csvr 0.6.6 → 0.6.8

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
  SHA1:
3
- metadata.gz: c504e551de84ae6f54fc9a8cf2320be373109af4
4
- data.tar.gz: 619340904f794ae994406d8e778568eee3062d14
3
+ metadata.gz: e9fb1eb6a9f70e01f636b04fad66ca2e1c0808f0
4
+ data.tar.gz: cc38a37a17b60c45f482df5575bfece1d6756474
5
5
  SHA512:
6
- metadata.gz: 3761793e745c6651278bcd55afa19e9717456bebe161958c3e83a2073ef6d54d7e65e9a14d123db9c145fc76dbcb1576796b7f13593e39acf1f8057a2cca92a6
7
- data.tar.gz: c99de7129fcb86e59a1351e5c69a464c1bc56709d16b9baca2efd5ffbca8c72ac8b4d09bb1a9c12718303e80f21888c080d5a61f27040ea18f879a51d6960098
6
+ metadata.gz: 0a7df7e589014af3f7f192a0ba77df05853c3fecb124e1f51503f464a9747cd10aed64903cb381f76fc1a2c832183e75d88841ea39b9d0249a85d01c8f0279d6
7
+ data.tar.gz: b31d2bfe60e898a3950b556e815ebbe0aac75ed53a74ce9e4cdd682ed6dcff2217339b5ac5deebf3d3ba9784d0ae903d7c59ef0ee83ef607008c3f82439667cf
data/lib/csvr.rb CHANGED
@@ -11,10 +11,10 @@ module CSVR
11
11
  return App.new(file)
12
12
  end
13
13
 
14
- class App
14
+ class App
15
15
 
16
16
  include CSVR::Parse
17
- include Format
17
+ include Format
18
18
 
19
19
  attr_reader :file, :rows
20
20
  attr_accessor :headers, :filters
@@ -26,6 +26,7 @@ module CSVR
26
26
  def parse
27
27
  @headers ||= CSVR::Parse.headers(@file)
28
28
  @rows = CSVR::Parse.rows(@file, @headers, @filters)
29
+ @types = CSVR::Parse.type(@headers, @rows[2])
29
30
  end
30
31
 
31
32
  def format
@@ -41,4 +42,3 @@ module CSVR
41
42
  end
42
43
  end
43
44
  end
44
-
data/lib/csvr/cli.rb CHANGED
@@ -10,7 +10,7 @@ module CSVR
10
10
  outputs = []
11
11
  outputs << "\trequire 'csvr' "
12
12
  outputs << "\tcsvr = CSVR.open('path/to/file')"
13
- outputs << "\t(optional) csvr.headers = ['array','of','custom', 'headers]"
13
+ outputs << "\t(optional) csvr.headers = ['array','of', 'headers]"
14
14
  outputs << "\t(optional) csvr.filters = ['array', 'of' 'strings' 'to' 'parse']"
15
15
  outputs << "\tcsvr.create('db_name', 'table_name')"
16
16
 
data/lib/csvr/format.rb CHANGED
@@ -3,12 +3,20 @@ module Format
3
3
 
4
4
  module_function
5
5
 
6
- #TODO: Interpret data types from the second line of a csv file
6
+ #TODO: Interpret data types from the second line of a csv file
7
7
  #TODO: Headers should reflect the data types of their rows
8
8
 
9
9
  def headers(headers)
10
- headers = headers.map { |h| "#{h} TEXT"}
11
- return headers.join(",")
10
+
11
+ headers = headers.map { |h| "#{h} TEXT" }.join(",")
12
+ return headers
13
+ end
14
+
15
+ def type(types)
16
+
17
+ #Convert Fixnum to Int, etc
18
+
19
+
12
20
  end
13
21
 
14
22
  def row(row)
@@ -19,4 +27,4 @@ module Format
19
27
  end
20
28
  return "(#{keys}) VALUES(#{values})"
21
29
  end
22
- end
30
+ end
data/lib/csvr/parse.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'csv'
2
2
 
3
- module CSVR
3
+ module CSVR
4
4
 
5
- module Parse
5
+ module Parse
6
6
 
7
7
  module_function
8
8
 
9
9
  def headers(file)
10
10
 
11
- File.open(file) do |fi|
12
- 1.times do
11
+ File.open(file) do |fi|
12
+ 1.times do
13
13
  return CSV.parse_line(fi.readline)
14
14
  end
15
15
  end
@@ -30,24 +30,24 @@ module CSVR
30
30
 
31
31
  File.open(file) do |fi|
32
32
 
33
- #TODO: Skip the first line. The code below creates an EOF Error
34
-
35
- # lines = fi.each_line
36
- # lines.next
33
+ #Skip the first line
34
+ lines = fi.each_line
35
+ lines.next
37
36
 
38
37
  values = []
39
38
  counter = 0
40
39
 
41
- maximum(file).times do
40
+ lines.each do |line|
42
41
 
43
42
  counter += 1
44
43
  puts "Parsing #{counter}"
45
44
 
46
- row = CSV.parse_line(fi.readline)
45
+ row = CSV.parse_line(line, :converters => :all)
47
46
 
48
47
  hash = {}
49
48
 
50
- index.each do |k, v|
49
+ #Remove ' punctation - this causes problems with the "INSERT INTO lines"
50
+ index.each do |k, v|
51
51
  row[k].gsub!(/[']/, '') if row[k].respond_to? :gsub
52
52
  hash[v] = row[k]
53
53
  end
@@ -72,8 +72,17 @@ module CSVR
72
72
  return nil
73
73
  end
74
74
 
75
- def maximum(file)
76
- return %x{wc -l < "#{file}"}.to_i
75
+ def type(headers, row)
76
+
77
+ types = []
78
+ headers.each do |header|
79
+ hash = {}
80
+ row.each do |k, v|
81
+ hash[k] = v.class if header.include?(k)
82
+ types << hash
83
+ end
84
+ end
85
+ return types.uniq
77
86
  end
78
87
  end
79
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Smith