bumblebee 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +7 -3
- data/Gemfile.lock +1 -1
- data/README.md +27 -19
- data/bin/console +15 -0
- data/lib/bumblebee/version.rb +1 -1
- data/spec/bumblebee/bumblebee_spec.rb +36 -2
- data/spec/bumblebee/fixtures/simple_readme_example.csv +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fc1683a1f73e0f3cfb12d5b718694519fb154d5201b35449730c9df7162a1aa
|
4
|
+
data.tar.gz: 3e73073d56e7996a848ee02c1b0d5082528f1c94d1bd5f1fb42b7dd20833e943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e565c2a8660b28c41e46d5e018e7656393db90fa9b9627387d829ed1f311a590ab617750177b83a453ce099313a3020fdb53d92ff771124a50033be679d0d69b
|
7
|
+
data.tar.gz: 85813743f37ad1094be77b0a182521b6873dc65ba2cbe830c107a21d4e2276471a9b2509cfca80a8e4f478566b7f5da3064b5b78c484b6bce25278d0230c59ef
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
+
# 1.2.1 (January 22, 2019)
|
2
|
+
|
3
|
+
* README enhancements.
|
4
|
+
|
1
5
|
# 1.2.0 (January 22, 2019)
|
2
6
|
|
3
|
-
|
7
|
+
* Updated parser so it is position-agnostic. Previously the position of the headers mattered to the parser. Now, the headers in the file will be used and matched on with the column headers.
|
4
8
|
|
5
9
|
# 1.1.0 (January 22, 2019)
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
* Updated parser so it is now compatible and works with Ruby 2.5.3 and 2.6.0.
|
12
|
+
* Minimum Ruby version bumped to 2.3.8
|
9
13
|
|
10
14
|
# 1.0.0 (December 27, 2018)
|
11
15
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/bluemarblepayroll/bumblebee.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/bumblebee)
|
4
4
|
|
5
|
-
Higher level languages, such as Ruby, make interacting with
|
5
|
+
Higher level languages, such as Ruby, make interacting with CSV (Comma Separated Values) files trivial. Even so, this library provides a very simple object/CSV mapper that allows you to fully interact with CSV's in a declarative way. Locking in common patterns, even in higher level languages, is important in large codebases. Using a library, such as this, will help ensure standardization around CSV interaction.
|
6
6
|
|
7
|
-
|
7
|
+
However, there are situations where this level of abstraciton may not be appropriate. For example, this library is not meant to be extremely performant given large files and/or datasets. This library shines with CSV and/or data-sets of less than 100,000 records (approx).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -34,7 +34,7 @@ id | name | dob | phone
|
|
34
34
|
|
35
35
|
Using the following column configuration:
|
36
36
|
|
37
|
-
````
|
37
|
+
````ruby
|
38
38
|
columns = [
|
39
39
|
{ field: :id },
|
40
40
|
{ field: :name },
|
@@ -45,14 +45,22 @@ columns = [
|
|
45
45
|
|
46
46
|
We could parse this data and turn it into hashes:
|
47
47
|
|
48
|
+
````ruby
|
49
|
+
objects = Bumblebee.parse_csv(columns, data)
|
48
50
|
````
|
49
|
-
|
51
|
+
|
52
|
+
Then `objects` is this array of hashes:
|
53
|
+
|
54
|
+
````ruby
|
55
|
+
[
|
56
|
+
{ id: '1', name: 'Matt', dob: '2/3/01', phone: '555-555-5555' },
|
57
|
+
{ id: '2', name: 'Nick', dob: '9/3/21', phone: '444-444-4444' },
|
58
|
+
{ id: '3', name: 'Sam', dob: '12/12/32', phone: '333-333-3333' }
|
59
|
+
]
|
50
60
|
````
|
51
61
|
|
52
62
|
*Note: Data, in this case, would be the read CSV file contents in string format.*
|
53
63
|
|
54
|
-
The variable `objects` would now be an array of hash objects.
|
55
|
-
|
56
64
|
### Custom Headers
|
57
65
|
|
58
66
|
If our headers are not a perfect 1:1 match to our object, such as:
|
@@ -65,7 +73,7 @@ ID # | First Name | Date of Birth | Phone #
|
|
65
73
|
|
66
74
|
Then we can explicitly map those as:
|
67
75
|
|
68
|
-
````
|
76
|
+
````ruby
|
69
77
|
columns = [
|
70
78
|
{ field: :id, header: 'ID #' },
|
71
79
|
{ field: :name, header: 'First Name' },
|
@@ -78,7 +86,7 @@ columns = [
|
|
78
86
|
|
79
87
|
Let's say we have the following data which we want to create a CSV from:
|
80
88
|
|
81
|
-
````
|
89
|
+
````ruby
|
82
90
|
objects = [
|
83
91
|
{
|
84
92
|
id: 1,
|
@@ -94,7 +102,7 @@ objects = [
|
|
94
102
|
},
|
95
103
|
{
|
96
104
|
id: 3,
|
97
|
-
name: { first: 'Sam' },
|
105
|
+
name: { first: 'Sam' },
|
98
106
|
demo: { dob: '1932-12-12' },
|
99
107
|
contact: { phone: '333-333-3333' }
|
100
108
|
}
|
@@ -111,7 +119,7 @@ ID # | First Name | Date of Birth | Phone #
|
|
111
119
|
|
112
120
|
Using the following column config:
|
113
121
|
|
114
|
-
````
|
122
|
+
````ruby
|
115
123
|
columns = [
|
116
124
|
{ field: :id, header: 'ID #' },
|
117
125
|
{ field: [:name, :first], header: 'First Name' },
|
@@ -122,8 +130,8 @@ columns = [
|
|
122
130
|
|
123
131
|
And executing the following:
|
124
132
|
|
125
|
-
````
|
126
|
-
csv =
|
133
|
+
````ruby
|
134
|
+
csv = Bumblebee.generate_csv(columns, objects)
|
127
135
|
````
|
128
136
|
|
129
137
|
The above columns config would work both ways, so if we received the CSV, we could parse it to an array of nested hashes. Unfortunately, for now, we cannot do better than an array of nested hashes.
|
@@ -132,25 +140,25 @@ The above columns config would work both ways, so if we received the CSV, we cou
|
|
132
140
|
|
133
141
|
You can also pass in functions that can do the value formatting. For example:
|
134
142
|
|
135
|
-
````
|
143
|
+
````ruby
|
136
144
|
columns = [
|
137
145
|
{
|
138
146
|
field: :id,
|
139
147
|
header: 'ID #'
|
140
148
|
},
|
141
149
|
{
|
142
|
-
field: :name,
|
143
|
-
header: 'First Name',
|
150
|
+
field: :name,
|
151
|
+
header: 'First Name',
|
144
152
|
to_csv: [:name, :first, ->(o) { o.to_s.upcase }]
|
145
153
|
},
|
146
154
|
{
|
147
|
-
field: :dob,
|
148
|
-
header: 'Date of Birth',
|
155
|
+
field: :dob,
|
156
|
+
header: 'Date of Birth',
|
149
157
|
to_csv: [:demo, :dob]
|
150
158
|
},
|
151
159
|
{
|
152
|
-
field: :phone,
|
153
|
-
header: 'Phone #',
|
160
|
+
field: :phone,
|
161
|
+
header: 'Phone #',
|
154
162
|
to_csv: [:contact, :phone]
|
155
163
|
}
|
156
164
|
]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bumblebee'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/lib/bumblebee/version.rb
CHANGED
@@ -37,7 +37,7 @@ describe ::Bumblebee do
|
|
37
37
|
let(:quoted_csv) { "\"name\",\"dob\"\n\"Matt\",\"1901-01-03\"\n\"Nathan\",\"1931-09-03\"\n" }
|
38
38
|
|
39
39
|
it 'should generate a csv' do
|
40
|
-
actual =
|
40
|
+
actual = Bumblebee.generate_csv(columns, people)
|
41
41
|
|
42
42
|
expect(actual).to eq(csv)
|
43
43
|
end
|
@@ -53,7 +53,7 @@ describe ::Bumblebee do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should parse a csv' do
|
56
|
-
objects =
|
56
|
+
objects = Bumblebee.parse_csv(columns, csv)
|
57
57
|
|
58
58
|
expect(objects).to eq(people)
|
59
59
|
end
|
@@ -63,4 +63,38 @@ describe ::Bumblebee do
|
|
63
63
|
|
64
64
|
expect(objects).to eq(people)
|
65
65
|
end
|
66
|
+
|
67
|
+
describe 'README examples' do
|
68
|
+
let(:columns) do
|
69
|
+
[
|
70
|
+
{ field: :id },
|
71
|
+
{ field: :name },
|
72
|
+
{ field: :dob },
|
73
|
+
{ field: :phone }
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:data) do
|
78
|
+
path = File.expand_path('fixtures/simple_readme_example.csv', __dir__)
|
79
|
+
|
80
|
+
# Excel adds a Byte Order Mark to the beginning of the file. Let Ruby
|
81
|
+
# know about this so that the first 'id' column is correctly parsed.
|
82
|
+
# More info about the Excel Byte Order Mark and Ruby is available at:
|
83
|
+
# https://estl.tech/of-ruby-and-hidden-csv-characters-ef482c679b35 .
|
84
|
+
file = File.open(path, 'r:bom|utf-8')
|
85
|
+
file.read
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:output) do
|
89
|
+
[
|
90
|
+
{ id: '1', name: 'Matt', dob: '2/3/01', phone: '555-555-5555' },
|
91
|
+
{ id: '2', name: 'Nick', dob: '9/3/21', phone: '444-444-4444' },
|
92
|
+
{ id: '3', name: 'Sam', dob: '12/12/32', phone: '333-333-3333' }
|
93
|
+
]
|
94
|
+
end
|
95
|
+
|
96
|
+
specify 'the simple 1:1 example works as advertised' do
|
97
|
+
expect(Bumblebee.parse_csv(columns, data)).to eq output
|
98
|
+
end
|
99
|
+
end
|
66
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumblebee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_hashable
|
@@ -71,7 +71,8 @@ description: |2
|
|
71
71
|
Even so, this library provides a very simple object/csv mapper that allows you to fully interact with CSVs in a declarative way.
|
72
72
|
email:
|
73
73
|
- mruggio@bluemarblepayroll.com
|
74
|
-
executables:
|
74
|
+
executables:
|
75
|
+
- console
|
75
76
|
extensions: []
|
76
77
|
extra_rdoc_files: []
|
77
78
|
files:
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- Guardfile
|
86
87
|
- LICENSE
|
87
88
|
- README.md
|
89
|
+
- bin/console
|
88
90
|
- bumblebee.gemspec
|
89
91
|
- lib/bumblebee.rb
|
90
92
|
- lib/bumblebee/bumblebee.rb
|
@@ -93,6 +95,7 @@ files:
|
|
93
95
|
- lib/bumblebee/version.rb
|
94
96
|
- spec/bumblebee/bumblebee_spec.rb
|
95
97
|
- spec/bumblebee/column_spec.rb
|
98
|
+
- spec/bumblebee/fixtures/simple_readme_example.csv
|
96
99
|
- spec/spec_helper.rb
|
97
100
|
homepage: https://github.com/bluemarblepayroll/bumblebee
|
98
101
|
licenses:
|
@@ -120,4 +123,5 @@ summary: Object/CSV Mapper
|
|
120
123
|
test_files:
|
121
124
|
- spec/bumblebee/bumblebee_spec.rb
|
122
125
|
- spec/bumblebee/column_spec.rb
|
126
|
+
- spec/bumblebee/fixtures/simple_readme_example.csv
|
123
127
|
- spec/spec_helper.rb
|