bmg 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: 9e90b71aeb478997a7f9efcea3a18cec7ad3fac3
4
- data.tar.gz: 9ebdd9b06a635ef12cef5d7c35d4746a56932bba
3
+ metadata.gz: c6fe9a06a0c6fbf5f5f0523b3ade5d59ac077c3b
4
+ data.tar.gz: 3d0dd15b128fe42a6eb603b922de1c8889d266c8
5
5
  SHA512:
6
- metadata.gz: a662b415f76df21dfad0d4e4b6f7c9dece45c994a7200c4d547f21007fd8158812a0e8c0fb263f0e4d3da597d334e03ed8394a28b052927f7f58081bf65ee392
7
- data.tar.gz: 520d850977384a3cff1aa7e8fe58f52ea34e9f7f8caa0d9ec1f4849a92bab50814bbdaeb4ad8b0cd551ab8b3424d1d57f42fbab51bbe22fa7f6824e5aa610159
6
+ metadata.gz: e608c650a868dc5d4870a6847675dbae8742525a53e255732c6634c85b911f31528d7a57cbd580eb74c3f85610590abfb0e792532a71dee23cf61b20e15aa713
7
+ data.tar.gz: 1b082e58ffce43e55e85ff36753b0d2d5e579e947a44010dd85a839e82ca4f6a371cb882ae32bc6b34e159936e0f21e1e8f8e944ef4ada4d43ff92ee48fa9b3d
@@ -14,7 +14,7 @@ module Bmg
14
14
 
15
15
  def each
16
16
  require 'roo'
17
- xlsx = Roo::Spreadsheet.open(@path)
17
+ xlsx = Roo::Spreadsheet.open(@path, @options)
18
18
  headers = nil
19
19
  xlsx.sheet(0)
20
20
  .each
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
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
  - Bernard Lambeau
@@ -89,18 +89,6 @@ files:
89
89
  - lib/bmg/reader/excel.rb
90
90
  - lib/bmg/relation.rb
91
91
  - lib/bmg/version.rb
92
- - spec/unit/operator/test_allbut.rb
93
- - spec/unit/operator/test_autosummarize.rb
94
- - spec/unit/operator/test_autowrap.rb
95
- - spec/unit/operator/test_project.rb
96
- - spec/unit/operator/test_rename.rb
97
- - spec/unit/reader/example.csv
98
- - spec/unit/reader/example.numbers
99
- - spec/unit/reader/example.xlsx
100
- - spec/unit/reader/test_csv.rb
101
- - spec/unit/reader/test_excel.rb
102
- - spec/unit/spec_helper.rb
103
- - spec/unit/test_relation.rb
104
92
  - tasks/gem.rake
105
93
  - tasks/test.rake
106
94
  homepage: http://github.com/enspirit/bmg
@@ -123,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
111
  version: '0'
124
112
  requirements: []
125
113
  rubyforge_project:
126
- rubygems_version: 2.5.1
114
+ rubygems_version: 2.5.2
127
115
  signing_key:
128
116
  specification_version: 4
129
117
  summary: Bmg is Alf's successor.
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Operator
4
- describe Allbut do
5
-
6
- it 'works' do
7
- allbut = Allbut.new [{ a: 1, b: 2 }], [:b]
8
- expect(allbut.to_a).to eql([{ a: 1 }])
9
- end
10
-
11
- it 'removes duplicates' do
12
- allbut = Allbut.new [{ a: 1, b: 2 }, { a: 1, b: 3 }], [:b]
13
- expect(allbut.to_a).to eql([{ a: 1 }])
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1,183 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Operator
4
- describe Autosummarize do
5
-
6
- context 'with empty by and no sums' do
7
- let(:by) { [] }
8
- let(:sums){ {} }
9
-
10
- it 'filters same tuples' do
11
- autosummarize = Autosummarize.new [
12
- { a: 1 },
13
- { a: 1 }
14
- ], by, sums
15
- expect(autosummarize.to_a).to eql([{ a: 1 }])
16
- end
17
- end
18
-
19
- context 'with a determinant and no sums' do
20
- let(:by) { [:a] }
21
- let(:sums){ {} }
22
-
23
- it 'applies Same to every unknown dependent' do
24
- autosummarize = Autosummarize.new [
25
- { a: 1, b: 2 },
26
- { a: 1, b: 2 },
27
- { a: 2, b: 2 },
28
- ], by, sums
29
- expect(autosummarize.to_a).to eql([
30
- { a: 1, b: 2 },
31
- { a: 2, b: 2 }
32
- ])
33
- end
34
- end
35
-
36
- context 'with a by and a DistinctList without comparator' do
37
- let(:by) { [ :id ] }
38
- let(:sums){ { :a => Autosummarize::DistinctList.new } }
39
-
40
- it 'groups as expected' do
41
- autosummarize = Autosummarize.new [
42
- { id: 1, a: 1 },
43
- { id: 1, a: 2 },
44
- { id: 2, a: 1 },
45
- { id: 1, a: 2 }
46
- ], by, sums
47
- expect(autosummarize.to_a).to eql([
48
- { id: 1, a: [1, 2] },
49
- { id: 2, a: [1] },
50
- ])
51
- end
52
-
53
- it 'ignores nulls' do
54
- autosummarize = Autosummarize.new [
55
- { id: 1, a: 1 },
56
- { id: 1, a: nil }
57
- ], by, sums
58
- expect(autosummarize.to_a).to eql([
59
- { id: 1, a: [1] },
60
- ])
61
- end
62
-
63
- it 'can be used to mimic the Group operator' do
64
- autosummarize = Autosummarize.new [
65
- { id: 1, a: { x: 1, y: 2 } },
66
- { id: 1, a: { x: 2, y: 2 } },
67
- { id: 2, a: { x: 1, y: 2 } },
68
- { id: 1, a: { x: 1, y: 2 } }
69
- ], by, sums
70
- expect(autosummarize.to_a).to eql([
71
- { id: 1, a: [{ x: 1, y: 2 }, { x: 2, y: 2 }] },
72
- { id: 2, a: [{ x: 1, y: 2 }] },
73
- ])
74
- end
75
-
76
- it 'supports the :group shortcut' do
77
- autosummarize = Autosummarize.new [
78
- { id: 1, a: 1 },
79
- { id: 1, a: 2 },
80
- { id: 2, a: 1 },
81
- { id: 1, a: 2 }
82
- ], by, { :a => :group }
83
- expect(autosummarize.to_a).to eql([
84
- { id: 1, a: [1, 2] },
85
- { id: 2, a: [1] },
86
- ])
87
- end
88
-
89
- end
90
-
91
- context 'with a by and a DistinctList with a comparator' do
92
- let(:by) { [ :id ] }
93
- let(:sums){ { :a => Autosummarize::DistinctList.new{|x,y| y <=> x } } }
94
-
95
- it 'groups as expected' do
96
- autosummarize = Autosummarize.new [
97
- { id: 1, a: 1 },
98
- { id: 1, a: 2 },
99
- { id: 2, a: 1 },
100
- { id: 1, a: 2 }
101
- ], by, sums
102
- expect(autosummarize.to_a).to eql([
103
- { id: 1, a: [2, 1] },
104
- { id: 2, a: [1] },
105
- ])
106
- end
107
- end
108
-
109
- context 'with a YByX ignoring nulls' do
110
- let(:by) { [ :id ] }
111
- let(:sums){ { :a => Autosummarize::YByX.new(:y, :x) } }
112
-
113
- it 'groups as expected and ignores nulls' do
114
- autosummarize = Autosummarize.new [
115
- { id: 1, a: { x: "foo", y: "bar" } },
116
- { id: 1, a: { x: "foo", y: "baz" } },
117
- { id: 1, a: { x: "gri", y: "gra" } },
118
- { id: 1, a: { x: "gro", y: nil } },
119
- { id: 1, a: { x: nil, y: "gru" } },
120
- ], by, sums
121
- expect(autosummarize.to_a).to eql([
122
- { id: 1, a: { "foo" => "baz", "gri" => "gra" } }
123
- ])
124
- end
125
- end
126
-
127
- context 'with a YByX preserving nulls' do
128
- let(:by) { [ :id ] }
129
- let(:sums){ { :a => Autosummarize::YByX.new(:y, :x, true) } }
130
-
131
- it 'groups as expected and ignores nulls' do
132
- autosummarize = Autosummarize.new [
133
- { id: 1, a: { x: "foo", y: "bar" } },
134
- { id: 1, a: { x: "foo", y: "baz" } },
135
- { id: 1, a: { x: "gri", y: "gra" } },
136
- { id: 1, a: { x: "gro", y: nil } },
137
- { id: 1, a: { x: nil, y: "gru" } },
138
- ], by, sums
139
- expect(autosummarize.to_a).to eql([
140
- { id: 1, a: { "foo" => "baz", "gri" => "gra", "gro" => nil } }
141
- ])
142
- end
143
- end
144
-
145
- context 'with a by and a YsByX and no sorter' do
146
- let(:by) { [ :id ] }
147
- let(:sums){ { :a => Autosummarize::YsByX.new(:y, :x) } }
148
-
149
- it 'filters same tuples' do
150
- autosummarize = Autosummarize.new [
151
- { id: 1, a: { x: 1, y: 3 } },
152
- { id: 1, a: { x: 1, y: 2 } },
153
- { id: 2, a: { x: 1, y: 1 } },
154
- { id: 1, a: { x: 2, y: 7 } }
155
- ], by, sums
156
- expect(autosummarize.to_a).to eql([
157
- { id: 1, a: { 1 => [3, 2], 2 => [7] } },
158
- { id: 2, a: { 1 => [1] } }
159
- ])
160
- end
161
- end
162
-
163
- context 'with a by and a YsByX and a sorter' do
164
- let(:by) { [ :id ] }
165
- let(:sums){ { :a => Autosummarize::YsByX.new(:y, :x){|u,v| u[:y] <=> v[:y] } } }
166
-
167
- it 'filters same tuples' do
168
- autosummarize = Autosummarize.new [
169
- { id: 1, a: { x: 1, y: 3 } },
170
- { id: 1, a: { x: 1, y: 2 } },
171
- { id: 2, a: { x: 1, y: 1 } },
172
- { id: 1, a: { x: 2, y: 7 } }
173
- ], by, sums
174
- expect(autosummarize.to_a).to eql([
175
- { id: 1, a: { 1 => [2, 3], 2 => [7] } },
176
- { id: 2, a: { 1 => [1] } }
177
- ])
178
- end
179
- end
180
-
181
- end
182
- end
183
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Operator
4
- describe 'Autowrap' do
5
-
6
- context 'when called in default mode' do
7
-
8
- it 'works as an array by default' do
9
- autowrap = Autowrap.new [{ a: 1, b: 2 }]
10
- expect(autowrap.to_a).to eql([{ a: 1, b: 2 }])
11
- end
12
-
13
- it 'wrap levels 1' do
14
- autowrap = Autowrap.new [{ a: 1, b_x: 2, b_y: 3 }]
15
- expect(autowrap.to_a).to eql([{ a: 1, b: { x: 2, y: 3 } }])
16
- end
17
-
18
- it 'wrap levels 2' do
19
- autowrap = Autowrap.new [{ a: 1, b_x_u: 2, b_y_v: 3, b_y_w: 4 }]
20
- expect(autowrap.to_a).to eql([{ a: 1, b: { x: { u: 2 }, y: { v: 3, w: 4 } } }])
21
- end
22
-
23
- it 'keeps LEFT JOIN nils unchanged' do
24
- autowrap = Autowrap.new [{ a: 1, b_x: nil, b_y: nil }]
25
- expect(autowrap.to_a).to eql([{ a: 1, b: { x: nil, y: nil } }])
26
- end
27
-
28
- end
29
-
30
- context 'when specifying the separator to use' do
31
-
32
- it 'works as expected' do
33
- autowrap = Autowrap.new [{ :a => 1, :"b.x.u" => 2, "b.y.v" => 3, "b.y.w" => 4 }], split: '.'
34
- expect(autowrap.to_a).to eql([{ a: 1, b: { x: { u: 2 }, y: { v: 3, w: 4 } } }])
35
- end
36
-
37
- end
38
-
39
- context 'when called with a Proc post processor' do
40
-
41
- let(:post) {
42
- ->(t,_){ t.delete(:user) if t[:user][:id].nil?; t }
43
- }
44
-
45
- it 'wrap levels 2' do
46
- aw = Autowrap.new [
47
- { user_id: 1, user_name: "foo", foo: "bar" },
48
- { user_id: nil, user_name: nil, foo: "baz" }
49
- ], postprocessor: post
50
- expected = [
51
- { user: {id: 1, name: "foo"}, foo: "bar" },
52
- { foo: "baz" }
53
- ]
54
- expect(aw.to_a).to eql(expected)
55
- end
56
-
57
- end
58
-
59
- context 'when called with :delete post processor' do
60
-
61
- it 'automatically removes the results of nil LEFT JOINs' do
62
- autowrap = Autowrap.new [{ a: 1, b_x: nil, b_y: nil }], postprocessor: :delete
63
- expect(autowrap.to_a).to eql([{ a: 1 }])
64
- end
65
-
66
- end
67
-
68
- context 'when called with :nil post processor' do
69
-
70
- it 'sets the results of nil LEFT JOINs to nil' do
71
- autowrap = Autowrap.new [{ a: 1, b_x: nil, b_y: nil }], postprocessor: :nil
72
- expect(autowrap.to_a).to eql([{ a: 1, b: nil }])
73
- end
74
-
75
- end
76
-
77
- context 'when called with a Hash post processor' do
78
-
79
- it 'sets the results of nil LEFT JOINs to nil' do
80
- autowrap = Autowrap.new [{ a: 1, b_x: nil, b_y: nil, c_x: nil, c_y: nil, d_x: nil }], postprocessor: { b: :nil, c: :delete }
81
- expect(autowrap.to_a).to eql([{ a: 1, b: nil, d: { x: nil } }])
82
- end
83
-
84
- end
85
-
86
- end
87
- end
88
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Operator
4
- describe Project do
5
-
6
- it 'works' do
7
- allbut = Project.new [{ a: 1, b: 2 }], [:b]
8
- expect(allbut.to_a).to eql([{ b: 2 }])
9
- end
10
-
11
- it 'removes duplicates' do
12
- allbut = Project.new [{ a: 1, b: 2 }, { a: 2, b: 2 }], [:b]
13
- expect(allbut.to_a).to eql([{ b: 2 }])
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Operator
4
- describe Rename do
5
-
6
- it 'works' do
7
- rename = Rename.new [{ a: 1, b: 2 }], :a => :x
8
- expect(rename.to_a).to eql([{ x: 1, b: 2 }])
9
- end
10
-
11
- end
12
- end
13
- end
@@ -1,3 +0,0 @@
1
- id;name
2
- 1;Bernard Lambeau
3
- 2;"Yoann;Guyot"
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Reader
4
- describe Csv do
5
-
6
- it 'works' do
7
- file = Path.dir/("example.csv")
8
- csv = Csv.new(file)
9
- expect(csv.to_a).to eql([
10
- {id: "1", name: "Bernard Lambeau"},
11
- {id: "2", name: "Yoann;Guyot"}
12
- ])
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- module Reader
4
- describe Csv do
5
-
6
- it 'works' do
7
- file = Path.dir/("example.xlsx")
8
- xlsx = Excel.new(file, skip: 1)
9
- expect(xlsx.to_a).to eql([
10
- {id: 1, name: "Bernard Lambeau"},
11
- {id: 2, name: "Yoann Guyot"}
12
- ])
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- require 'rspec'
2
- require 'bmg'
3
- require 'path'
4
-
5
- module SpecHelper
6
-
7
- end
8
-
9
- RSpec.configure do |c|
10
- c.include SpecHelper
11
- end
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
- module Bmg
3
- describe Relation do
4
-
5
- shared_examples_for "an operator method" do
6
-
7
- it 'returns a relation' do
8
- expect(subject).to be_a(Relation)
9
- end
10
-
11
- end
12
-
13
- describe 'allbut' do
14
- let(:relation) {
15
- Relation.new([
16
- { a: 1, b: 2 },
17
- { a: 1, b: 4 },
18
- { a: 3, b: 4 }
19
- ])
20
- }
21
-
22
- subject {
23
- relation.allbut([:b])
24
- }
25
-
26
- it_behaves_like "an operator method"
27
-
28
- it 'returns the exected result' do
29
- expect(subject.to_a).to eql([
30
- { a: 1 },
31
- { a: 3 }
32
- ])
33
- end
34
- end
35
-
36
- describe 'autosummarize' do
37
- let(:relation) {
38
- Relation.new([
39
- { a: 1, x: 2 },
40
- { a: 1, x: 4 }
41
- ])
42
- }
43
-
44
- subject {
45
- relation.autosummarize([:a], x: Operator::Autosummarize::DistinctList.new)
46
- }
47
-
48
- it_behaves_like "an operator method"
49
-
50
- it 'returns the exected result' do
51
- expect(subject.to_a).to eql([
52
- { a: 1, x: [2, 4] }
53
- ])
54
- end
55
- end
56
-
57
- describe 'autowrap' do
58
- let(:relation) {
59
- Relation.new([
60
- { a: 1, b_x: 2, b_y: 3 },
61
- { a: 2, b_x: 4, b_y: 1 }
62
- ])
63
- }
64
-
65
- subject {
66
- relation.autowrap
67
- }
68
-
69
- it_behaves_like "an operator method"
70
-
71
- it 'returns the exected result' do
72
- expect(subject.to_a).to eql([
73
- { a: 1, b: { x: 2, y: 3 } },
74
- { a: 2, b: { x: 4, y: 1 } }
75
- ])
76
- end
77
-
78
- it 'passes the options' do
79
- expect(relation.autowrap(split: ".").to_a).to eql([
80
- { a: 1, b_x: 2, b_y: 3 },
81
- { a: 2, b_x: 4, b_y: 1 }
82
- ])
83
- end
84
- end
85
-
86
- describe 'project' do
87
- let(:relation) {
88
- Relation.new([
89
- { a: 1, b: 2 },
90
- { a: 1, b: 4 },
91
- { a: 3, b: 4 }
92
- ])
93
- }
94
-
95
- subject {
96
- relation.project([:b])
97
- }
98
-
99
- it_behaves_like "an operator method"
100
-
101
- it 'returns the exected result' do
102
- expect(subject.to_a).to eql([
103
- { b: 2 },
104
- { b: 4 }
105
- ])
106
- end
107
- end
108
-
109
- describe 'rename' do
110
- let(:relation) {
111
- Relation.new([
112
- { a: 1, b: 2 },
113
- { a: 2, b: 4 }
114
- ])
115
- }
116
-
117
- subject {
118
- relation.rename(b: :c)
119
- }
120
-
121
- it_behaves_like "an operator method"
122
-
123
- it 'returns the exected result' do
124
- expect(subject.to_a).to eql([
125
- { a: 1, c: 2 },
126
- { a: 2, c: 4 }
127
- ])
128
- end
129
- end
130
-
131
- end # describe Relation
132
- end # module Bmg