typedcsv 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d01bbde2f4dc34fe2d698b490c2d786b8a5549
4
- data.tar.gz: 54f8597c317508902b6709c308ba14eb45aa48da
3
+ metadata.gz: 315765b481130f95049fe7549a29fc3e7722fd20
4
+ data.tar.gz: 070a5e9194663ba62113a2a7a87e6976fd2f86df
5
5
  SHA512:
6
- metadata.gz: 51e70f6b102ff7e8b91fd36899a4ac06960564444ebbabb5925533901f5de39abf804c28ced2af41d662eef2d21a703fe0eb631ad8d29874a4d27fa0548eead0
7
- data.tar.gz: 6a844258d5e748328b87787e901c36d8c6e3a7daf43ad18d3f02c703942f31187ab936c7498040e7f139a98b94da80ed0ff370c39ba879fa8fd448cb7ed65bf6
6
+ metadata.gz: ce70f197882f1103c71c108f9e97722712ced83c1f82365cd9a4b154f6a8bb032268ff822ec3ada4ec1c39f076b6b46b6388a45721bfded88bdd6dbda8468ea2
7
+ data.tar.gz: '0280d2e3c7137c80dce8cf30e2c0b680e9f5bd1330575254e35ca942cdace950dc5dca7d0c1a3c46582131a1b179a00736cff9908df3bf934f8a7bbf2f2aa3ce'
data/CHANGELOG ADDED
@@ -0,0 +1,13 @@
1
+ 0.1.0 / 2017-09-06
2
+
3
+ Initial version!
4
+
5
+ 0.1.1 / 2017-09-06
6
+
7
+ Enhancements
8
+
9
+ * boolean type
10
+
11
+ Bug fixes
12
+
13
+ * Handles null (empty string) across types
data/README.md CHANGED
@@ -3,15 +3,15 @@
3
3
  Here's your standard untyped CSV:
4
4
 
5
5
  ```
6
- name,income,created_at,tags
7
- Seamus,12301.2,2012-02-21,red;blue
6
+ name,income,created_at,tags,great
7
+ Seamus,12301.2,2012-02-21,red;blue,true
8
8
  ```
9
9
 
10
10
  Now, you and I know that `12301.2` is a number and `2012-02-21` is a date and `red;blue` is a list... so let's just write that into the headers:
11
11
 
12
12
  ```
13
- name,income:number,created_at:date,tags:list
14
- Seamus,12301.2,2012-02-21,red;blue
13
+ name,income:number,created_at:date,tags:list,great:boolean
14
+ Seamus,12301.2,2012-02-21,red;blue,true
15
15
  ```
16
16
 
17
17
  Now let's parse it:
@@ -21,6 +21,7 @@ Typedcsv.foreach('file.csv', headers: true) do |row|
21
21
  row['income'] # will be a Float
22
22
  row['created_at'] # will be a Date
23
23
  row['tags'] # will be an Array
24
+ row['great'] # will be TrueClass or FalseClass
24
25
  end
25
26
  ```
26
27
 
@@ -33,6 +34,7 @@ This gem provides `Typedcsv.foreach()`, which takes exactly the same arguments a
33
34
  * list (must be semicolon-separated)
34
35
  * date (must be ISO8601)
35
36
  * time (must be ISO8601)
37
+ * boolean (recognizes "true" or "false")
36
38
 
37
39
  ## Benchmarks
38
40
 
data/lib/typedcsv.rb CHANGED
@@ -44,6 +44,9 @@ class Typedcsv
44
44
  end
45
45
 
46
46
  class Headers
47
+ TRUE = 'true'
48
+ FALSE = 'false'
49
+ EMPTY_STRING = ''
47
50
  attr_reader :raw
48
51
  def initialize(raw)
49
52
  @raw = raw
@@ -72,10 +75,20 @@ class Typedcsv
72
75
  end
73
76
  private
74
77
  def convert(type, v)
78
+ if v.nil? or v == EMPTY_STRING
79
+ return nil
80
+ end
75
81
  case type
76
82
  when 'text'
77
83
  # defaults to no parsing
78
84
  v
85
+ when 'boolean'
86
+ case v
87
+ when TRUE
88
+ true
89
+ when FALSE
90
+ false
91
+ end
79
92
  when 'list'
80
93
  CSV.parse_line(v, col_sep: ';')
81
94
  when 'date'
@@ -1,3 +1,3 @@
1
1
  class Typedcsv
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typedcsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -62,6 +62,7 @@ files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
+ - CHANGELOG
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
67
68
  - LICENSE.txt