bumblebee 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/bumblebee/template.rb +3 -9
- data/lib/bumblebee/version.rb +1 -1
- data/spec/bumblebee/bumblebee_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65ab8c72986bdae30dd8ed596620fff17751a35ea0f5e46ac8cf3b038d13d309
|
4
|
+
data.tar.gz: 756adec9d9ffd8dfb239effc74b908b73190e4c3f023c83bc44d93114bf77cf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40ddf7bed866c0a3ab76357c4c9a1c89a7e28ef7e31d68b2260fea25a422dc321dd14ef59c4e9ccda714e6270707f15744307c54505903658336afb482cc7a56
|
7
|
+
data.tar.gz: bac2237f95edee3ff77c83c0f05886b933f910d803921752e7354395896349b565b5f7611694900b91e29b4a2c51a450421f57c96eebe94f7da7b9a65dc93e99
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 1.2.0 (January 22, 2019)
|
2
|
+
|
3
|
+
- 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
|
+
|
1
5
|
# 1.1.0 (January 22, 2019)
|
2
6
|
|
3
7
|
- Updated parser so it is now compatible and works with Ruby 2.5.3 and 2.6.0.
|
data/Gemfile.lock
CHANGED
data/lib/bumblebee/template.rb
CHANGED
@@ -26,7 +26,7 @@ module Bumblebee
|
|
26
26
|
def generate_csv(objects, options = {})
|
27
27
|
objects = objects.is_a?(Hash) ? [objects] : Array(objects)
|
28
28
|
|
29
|
-
write_options =
|
29
|
+
write_options = options.merge(headers: headers, write_headers: true)
|
30
30
|
|
31
31
|
CSV.generate(write_options) do |csv|
|
32
32
|
objects.each do |object|
|
@@ -38,10 +38,10 @@ module Bumblebee
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def parse_csv(string, options = {})
|
41
|
-
csv = CSV.new(string,
|
41
|
+
csv = CSV.new(string, options.merge(headers: true))
|
42
42
|
|
43
43
|
# Drop the first record, it is the header record
|
44
|
-
csv.to_a
|
44
|
+
csv.to_a.map do |row|
|
45
45
|
# Build up a hash using the column one at a time
|
46
46
|
extracted_hash = columns.inject({}) do |hash, column|
|
47
47
|
hash.merge(column.csv_to_object(row))
|
@@ -50,11 +50,5 @@ module Bumblebee
|
|
50
50
|
extracted_hash
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def make_options(options = {})
|
57
|
-
options.merge(headers: headers)
|
58
|
-
end
|
59
53
|
end
|
60
54
|
end
|
data/lib/bumblebee/version.rb
CHANGED
@@ -18,6 +18,13 @@ describe ::Bumblebee do
|
|
18
18
|
]
|
19
19
|
end
|
20
20
|
|
21
|
+
let(:reverse_columns) do
|
22
|
+
[
|
23
|
+
{ field: :dob },
|
24
|
+
{ field: :name }
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
21
28
|
let(:people) do
|
22
29
|
[
|
23
30
|
{ name: 'Matt', dob: '1901-01-03' },
|
@@ -50,4 +57,10 @@ describe ::Bumblebee do
|
|
50
57
|
|
51
58
|
expect(objects).to eq(people)
|
52
59
|
end
|
60
|
+
|
61
|
+
it 'should parse a csv with columns in different order than headers' do
|
62
|
+
objects = ::Bumblebee.parse_csv(reverse_columns, csv)
|
63
|
+
|
64
|
+
expect(objects).to eq(people)
|
65
|
+
end
|
53
66
|
end
|