bumblebee 2.1.0 → 3.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.
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2018-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ class ConverterTestCase
11
+ ALL = [
12
+ {
13
+ arg: {
14
+ type: :bigdecimal,
15
+ nullable: true
16
+ },
17
+ convert_cases: [
18
+ [nil, nil],
19
+ ['', nil],
20
+ [6, BigDecimal(6)],
21
+ [BigDecimal('12'), BigDecimal(12)],
22
+ ['24.35', BigDecimal('24.35')]
23
+ ]
24
+ },
25
+ {
26
+ arg: {
27
+ type: :bigdecimal,
28
+ nullable: false
29
+ },
30
+ convert_cases: [
31
+ [nil, BigDecimal(0)],
32
+ ['', BigDecimal(0)]
33
+ ]
34
+ },
35
+ {
36
+ arg: {
37
+ type: :boolean,
38
+ nullable: true
39
+ },
40
+ convert_cases: [
41
+ [nil, nil],
42
+ [true, true],
43
+ ['t', true],
44
+ ['true', true],
45
+ ['TRUE', true],
46
+ ['True', true],
47
+ ['1', true],
48
+ ['Y', true],
49
+ ['y', true],
50
+ ['yes', true],
51
+ ['YES', true],
52
+ ['Yes', true],
53
+ [false, false],
54
+ ['f', false],
55
+ ['false', false],
56
+ ['FALSE', false],
57
+ ['False', false],
58
+ ['0', false],
59
+ ['N', false],
60
+ ['n', false],
61
+ ['no', false],
62
+ ['NO', false],
63
+ ['No', false]
64
+ ]
65
+ },
66
+ {
67
+ arg: {
68
+ type: :boolean,
69
+ nullable: false
70
+ },
71
+ convert_cases: [
72
+ [nil, false],
73
+ ['', false]
74
+ ]
75
+ },
76
+ {
77
+ arg: {
78
+ type: :float,
79
+ nullable: true
80
+ },
81
+ convert_cases: [
82
+ [nil, nil],
83
+ ['', nil],
84
+ [6, 6.to_f],
85
+ [6.0, 6.0.to_f],
86
+ ['24.35', '24.35'.to_f]
87
+ ]
88
+ },
89
+ {
90
+ arg: {
91
+ type: :float,
92
+ nullable: false
93
+ },
94
+ convert_cases: [
95
+ [nil, 0.0],
96
+ ['', 0.0]
97
+ ]
98
+ }
99
+ ].freeze
100
+
101
+ class << self
102
+ def all
103
+ @all ||= ALL.map { |c| new(c) }
104
+ end
105
+ end
106
+
107
+ attr_reader :arg, :convert_cases
108
+
109
+ def initialize(arg:, convert_cases:)
110
+ @arg = arg
111
+ @convert_cases = convert_cases
112
+ end
113
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2018-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ class PersonTemplate < ::Bumblebee::Template
11
+ column 'ID #', property: 'id',
12
+ to_object: :integer
13
+
14
+ column 'First Name', property: 'first',
15
+ through: 'demo'
16
+
17
+ column 'Last Name', property: 'last',
18
+ through: 'demo'
19
+
20
+ column 'Street 1', property: 'street1',
21
+ through: %w[demo address]
22
+
23
+ column 'Street 2', property: 'street2',
24
+ through: %w[demo address]
25
+
26
+ column 'City', property: 'city',
27
+ through: %w[demo address]
28
+
29
+ column 'State', property: 'st',
30
+ through: %w[demo address]
31
+
32
+ column 'Zipcode', property: 'zip',
33
+ through: %w[demo address]
34
+
35
+ column 'Current', property: 'current',
36
+ through: %w[demo address],
37
+ to_object: :boolean
38
+
39
+ column 'Home #', property: 'home',
40
+ through: 'contact'
41
+
42
+ column 'Fax #', property: 'fax',
43
+ through: 'contact'
44
+
45
+ column 'Email Address', property: 'email',
46
+ through: 'contact'
47
+
48
+ column 'Smokes', property: 'smoker',
49
+ to_object: :boolean
50
+
51
+ column 'Current Balance', property: 'balance',
52
+ to_object: :bigdecimal
53
+
54
+ column 'Visits', property: 'visit_dates',
55
+ to_csv: { type: :join, separator: ';', per: :string },
56
+ to_object: { type: :split, separator: ';', per: :date }
57
+
58
+ column 'Family Members', property: 'family_members',
59
+ to_csv: { type: :pluck_join, sub_property: 'id' },
60
+ to_object: { type: :pluck_split, sub_property: 'id', per: :integer }
61
+
62
+ column 'Email Address Domain', property: 'email',
63
+ through: 'contact',
64
+ to_csv: ->(email) { email.to_s.split('@').last },
65
+ to_object: :ignore
66
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2018-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ class SimpleObject
11
+ attr_accessor :id, :name, :dob, :phone
12
+
13
+ def initialize(id: nil, name: '', dob: nil, phone: '')
14
+ @id = id
15
+ @name = name
16
+ @dob = dob
17
+ @phone = phone
18
+ end
19
+
20
+ def eql?(other)
21
+ id == other.id && name == other.name && dob == other.dob && phone == other.phone
22
+ end
23
+
24
+ def ==(other)
25
+ eql?(other)
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ ID #,First Name,Last Name,Street 1,Street 2,City,State,Zipcode,Current,Home #,Fax #,Email Address,Smokes,Current Balance,Visits,Family Members,Email Address Domain
2
+ 1,Matt,Rizzo,555 Happy Ln.,Suite 208,Mukwongo,WI,12345,true,555-444-5555,555-444-5555,something@somewhere.org,false,124.53,2018-03-02;2018-06-04,"3,4",somewhere.org
3
+ 2,Katie,Bunny,765 N. Hollywood Dr.,Apt 3B,Bel Air,CA,99999,false,123-456-7890,098-765-4321,st@elsewhere.org,true,-98.5,2010-09-10;2018-03-04,"5,6",elsewhere.org
@@ -0,0 +1,46 @@
1
+ - id: 1
2
+ demo:
3
+ first: Matt
4
+ last: Rizzo
5
+ address:
6
+ street1: 555 Happy Ln.
7
+ street2: Suite 208
8
+ city: Mukwongo
9
+ st: WI
10
+ zip: '12345'
11
+ current: true
12
+ contact:
13
+ home: 555-444-5555
14
+ fax: 555-444-5555
15
+ email: something@somewhere.org
16
+ smoker: false
17
+ balance: 124.53
18
+ visit_dates:
19
+ - 2018-03-02
20
+ - 2018-06-04
21
+ family_members:
22
+ - id: 3
23
+ - id: 4
24
+ - id: 2
25
+ demo:
26
+ first: Katie
27
+ last: Bunny
28
+ address:
29
+ street1: 765 N. Hollywood Dr.
30
+ street2: Apt 3B
31
+ city: Bel Air
32
+ st: CA
33
+ zip: '99999'
34
+ current: false
35
+ contact:
36
+ home: 123-456-7890
37
+ fax: 098-765-4321
38
+ email: st@elsewhere.org
39
+ smoker: true
40
+ balance: -98.5
41
+ visit_dates:
42
+ - 2010-09-10
43
+ - 2018-03-04
44
+ family_members:
45
+ - id: 5
46
+ - id: 6
@@ -0,0 +1,35 @@
1
+ 'ID #':
2
+ property: id
3
+ to_object: integer
4
+ 'Plate #':
5
+ property: plate
6
+ Date:
7
+ property: registration_date
8
+ to_object: date
9
+ 'Person ID #':
10
+ property: id
11
+ through: person
12
+ to_object: integer
13
+ First Name:
14
+ property: first
15
+ through: person
16
+ Middle Name:
17
+ property: middle
18
+ through: person
19
+ Last Name:
20
+ property: last
21
+ through: person
22
+ 'Car ID #':
23
+ property: id
24
+ through: car
25
+ to_object: integer
26
+ Make:
27
+ property: make
28
+ through: car
29
+ Model:
30
+ property: model
31
+ through: car
32
+ Year:
33
+ property: year
34
+ through: car
35
+ to_object: integer
@@ -0,0 +1,3 @@
1
+ ID #,Plate #,Date,Person ID #,First Name,Middle Name,Last Name,Car ID #,Make,Model,Year
2
+ 1,No1BBALL,2018-01-02,2,Michael,Jeffery,Jordan,3,Jeep,Wrangler,2018
3
+ 4,No2BBALL,2018-09-02,5,Scottie,Maurice,Pippen,6,Toyota,Camry,1999
@@ -0,0 +1,26 @@
1
+ - id: 1
2
+ registration_date: 2018-01-02
3
+ plate: No1BBALL
4
+ person:
5
+ id: 2
6
+ first: Michael
7
+ middle: Jeffery
8
+ last: Jordan
9
+ car:
10
+ id: 3
11
+ make: Jeep
12
+ model: Wrangler
13
+ year: 2018
14
+ - id: 4
15
+ registration_date: 2018-09-02
16
+ plate: No2BBALL
17
+ person:
18
+ id: 5
19
+ first: Scottie
20
+ middle: Maurice
21
+ last: Pippen
22
+ car:
23
+ id: 6
24
+ make: Toyota
25
+ model: Camry
26
+ year: 1999
@@ -0,0 +1,4 @@
1
+ - id
2
+ - name
3
+ - dob
4
+ - phone
@@ -1,4 +1,4 @@
1
- ID #,First Name,Date of Birth,Phone #
1
+ id,name,dob,phone
2
2
  1,Matt,1901-02-03,555-555-5555
3
3
  2,Nick,1921-09-03,444-444-4444
4
4
  3,Sam,1932-12-12,333-333-3333
@@ -0,0 +1,12 @@
1
+ - id: '1'
2
+ name: Matt
3
+ dob: '1901-02-03'
4
+ phone: 555-555-5555
5
+ - id: '2'
6
+ name: Nick
7
+ dob: '1921-09-03'
8
+ phone: 444-444-4444
9
+ - id: '3'
10
+ name: Sam
11
+ dob: '1932-12-12'
12
+ phone: 333-333-3333
@@ -9,6 +9,7 @@
9
9
 
10
10
  require 'stringio'
11
11
  require 'pry'
12
+ require 'ostruct'
12
13
 
13
14
  require 'simplecov'
14
15
  require 'simplecov-console'
@@ -17,16 +18,41 @@ SimpleCov.start
17
18
 
18
19
  require './lib/bumblebee'
19
20
 
20
- def fixture_path(filename)
21
+ def fixture_path(*filename)
21
22
  File.join('spec', 'fixtures', filename)
22
23
  end
23
24
 
24
- def fixture(filename)
25
+ def csv_fixture(*filename)
26
+ CSV.new(fixture(*filename), headers: true).map(&:to_h)
27
+ end
28
+
29
+ def yaml_fixture(*filename)
30
+ # rubocop:disable Security/YAMLLoad
31
+ YAML.load(fixture(*filename))
32
+ # rubocop:enable Security/YAMLLoad
33
+ end
34
+
35
+ def fixture(*filename)
25
36
  # Excel adds a Byte Order Mark to the beginning of the file. Let Ruby
26
37
  # know about this so that the first 'id' column is correctly parsed.
27
38
  # More info about the Excel Byte Order Mark and Ruby is available at:
28
39
  # https://estl.tech/of-ruby-and-hidden-csv-characters-ef482c679b35 .
29
- file = File.open(fixture_path(filename), 'r:bom|utf-8')
40
+ file = File.open(fixture_path(*filename), 'r:bom|utf-8')
30
41
 
31
42
  file.read
32
43
  end
44
+
45
+ def manually_convert_csv_object(csv_object, columns)
46
+ csv_object.map do |header, value|
47
+ column = ::Bumblebee::Column.new(header, columns[header].symbolize_keys)
48
+
49
+ converted_value =
50
+ if column.extractor.expect_array?
51
+ value
52
+ else
53
+ column.converter.convert(value)
54
+ end
55
+
56
+ [header, converted_value]
57
+ end.to_h
58
+ 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: 2.1.0
4
+ version: 3.0.0
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-03-04 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -134,13 +134,29 @@ files:
134
134
  - lib/bumblebee.rb
135
135
  - lib/bumblebee/bumblebee.rb
136
136
  - lib/bumblebee/column.rb
137
+ - lib/bumblebee/column_dsl.rb
138
+ - lib/bumblebee/column_set.rb
139
+ - lib/bumblebee/converter.rb
140
+ - lib/bumblebee/core_ext/hash.rb
141
+ - lib/bumblebee/mutator.rb
142
+ - lib/bumblebee/null_converter.rb
143
+ - lib/bumblebee/object_interface.rb
144
+ - lib/bumblebee/simple_converter.rb
137
145
  - lib/bumblebee/template.rb
138
146
  - lib/bumblebee/version.rb
139
- - spec/bumblebee/bumblebee_spec.rb
140
- - spec/bumblebee/column_spec.rb
147
+ - spec/bumblebee/simple_converter_spec.rb
141
148
  - spec/bumblebee/template_spec.rb
142
- - spec/fixtures/custom_readme_example.csv
143
- - spec/fixtures/simple_readme_example.csv
149
+ - spec/examples/converter_test_case.rb
150
+ - spec/examples/person_template.rb
151
+ - spec/examples/simple_object.rb
152
+ - spec/fixtures/people/data.csv
153
+ - spec/fixtures/people/data.yml
154
+ - spec/fixtures/registrations/columns.yml
155
+ - spec/fixtures/registrations/data.csv
156
+ - spec/fixtures/registrations/data.yml
157
+ - spec/fixtures/simple/columns.yml
158
+ - spec/fixtures/simple/data.csv
159
+ - spec/fixtures/simple/data.yml
144
160
  - spec/spec_helper.rb
145
161
  homepage: https://github.com/bluemarblepayroll/bumblebee
146
162
  licenses:
@@ -166,9 +182,17 @@ signing_key:
166
182
  specification_version: 4
167
183
  summary: Object/CSV Mapper
168
184
  test_files:
169
- - spec/bumblebee/bumblebee_spec.rb
170
- - spec/bumblebee/column_spec.rb
185
+ - spec/bumblebee/simple_converter_spec.rb
171
186
  - spec/bumblebee/template_spec.rb
172
- - spec/fixtures/custom_readme_example.csv
173
- - spec/fixtures/simple_readme_example.csv
187
+ - spec/examples/converter_test_case.rb
188
+ - spec/examples/person_template.rb
189
+ - spec/examples/simple_object.rb
190
+ - spec/fixtures/people/data.csv
191
+ - spec/fixtures/people/data.yml
192
+ - spec/fixtures/registrations/columns.yml
193
+ - spec/fixtures/registrations/data.csv
194
+ - spec/fixtures/registrations/data.yml
195
+ - spec/fixtures/simple/columns.yml
196
+ - spec/fixtures/simple/data.csv
197
+ - spec/fixtures/simple/data.yml
174
198
  - spec/spec_helper.rb