csvr 0.6.8 → 1.0.0
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 +4 -4
- data/lib/csvr/format.rb +7 -12
- data/lib/csvr/parse.rb +2 -1
- data/lib/csvr.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6b03d9b873a4adb1045f2226a53c438c3ca92bb
|
4
|
+
data.tar.gz: 808c8e8f909e8c6affcd336a507078054940616f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7377753f0bcce3c813834dcbe498cf7d8287450ca23bc58b0385456771ee8e12b1584d398c029e9432add6df77c1f476ad98238ecbc60250836bcbf479908419
|
7
|
+
data.tar.gz: ff22d7cb0e384e13b937fecf33e01e41e6eb754559c3c7b4a405e6f711ae6a24f1b460df2a2747cd0f7ee6fdd34e126868e323629137fc766b05a685a63b0d10
|
data/lib/csvr/format.rb
CHANGED
@@ -3,24 +3,19 @@ module Format
|
|
3
3
|
|
4
4
|
module_function
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def headers(headers)
|
10
|
-
|
11
|
-
headers = headers.map { |h| "#{h} TEXT" }.join(",")
|
6
|
+
def headers(headers, types)
|
7
|
+
headers = headers.map { |h| "#{h} #{type(h, types)}" }.join(",")
|
12
8
|
return headers
|
13
9
|
end
|
14
10
|
|
15
|
-
def type(types)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def type(header, types)
|
12
|
+
#This can be done better I am sure
|
13
|
+
return "TEXT" unless types[header] == Fixnum || Float
|
14
|
+
return "INTEGER" unless types[header] == Float
|
15
|
+
return "REAL"
|
20
16
|
end
|
21
17
|
|
22
18
|
def row(row)
|
23
|
-
|
24
19
|
if row.is_a? Hash
|
25
20
|
values = row.values.map { |r| "'#{r}'"}.join(",")
|
26
21
|
keys = row.keys.join(",")
|
data/lib/csvr/parse.rb
CHANGED
data/lib/csvr.rb
CHANGED
@@ -3,6 +3,8 @@ require_relative 'csvr/format'
|
|
3
3
|
require_relative 'csvr/sqlitedb'
|
4
4
|
require_relative 'csvr/cli'
|
5
5
|
|
6
|
+
#TODO: COMMAND LINE OPTIONS?
|
7
|
+
|
6
8
|
module CSVR
|
7
9
|
|
8
10
|
module_function
|
@@ -16,7 +18,7 @@ module CSVR
|
|
16
18
|
include CSVR::Parse
|
17
19
|
include Format
|
18
20
|
|
19
|
-
attr_reader :file, :rows
|
21
|
+
attr_reader :file, :rows, :types
|
20
22
|
attr_accessor :headers, :filters
|
21
23
|
|
22
24
|
def initialize(file)
|
@@ -26,11 +28,11 @@ module CSVR
|
|
26
28
|
def parse
|
27
29
|
@headers ||= CSVR::Parse.headers(@file)
|
28
30
|
@rows = CSVR::Parse.rows(@file, @headers, @filters)
|
29
|
-
@types = CSVR::Parse.type(@headers, @rows[
|
31
|
+
@types = CSVR::Parse.type(@headers, @rows[1])
|
30
32
|
end
|
31
33
|
|
32
34
|
def format
|
33
|
-
@headers = Format.headers(@headers)
|
35
|
+
@headers = Format.headers(@headers, @types)
|
34
36
|
@rows = @rows.map{ |row| Format.row(row) }
|
35
37
|
end
|
36
38
|
|