bmg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE.md +22 -0
- data/README.md +3 -0
- data/Rakefile +11 -0
- data/lib/bmg.rb +18 -0
- data/lib/bmg/operator.rb +14 -0
- data/lib/bmg/operator/allbut.rb +44 -0
- data/lib/bmg/operator/autosummarize.rb +190 -0
- data/lib/bmg/operator/autowrap.rb +109 -0
- data/lib/bmg/operator/project.rb +43 -0
- data/lib/bmg/operator/rename.rb +45 -0
- data/lib/bmg/reader.rb +11 -0
- data/lib/bmg/reader/csv.rb +56 -0
- data/lib/bmg/reader/excel.rb +35 -0
- data/lib/bmg/relation.rb +34 -0
- data/lib/bmg/version.rb +8 -0
- data/spec/unit/operator/test_allbut.rb +18 -0
- data/spec/unit/operator/test_autosummarize.rb +183 -0
- data/spec/unit/operator/test_autowrap.rb +88 -0
- data/spec/unit/operator/test_project.rb +18 -0
- data/spec/unit/operator/test_rename.rb +13 -0
- data/spec/unit/reader/example.csv +3 -0
- data/spec/unit/reader/example.numbers +0 -0
- data/spec/unit/reader/example.xlsx +0 -0
- data/spec/unit/reader/test_csv.rb +17 -0
- data/spec/unit/reader/test_excel.rb +17 -0
- data/spec/unit/spec_helper.rb +11 -0
- data/spec/unit/test_relation.rb +132 -0
- data/tasks/gem.rake +39 -0
- data/tasks/test.rake +17 -0
- metadata +130 -0
@@ -0,0 +1,18 @@
|
|
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
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,132 @@
|
|
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
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems/package_task'
|
2
|
+
|
3
|
+
# Dynamically load the gem spec
|
4
|
+
gemspec_file = File.expand_path('../../bmg.gemspec', __FILE__)
|
5
|
+
gemspec = Kernel.eval(File.read(gemspec_file))
|
6
|
+
|
7
|
+
Gem::PackageTask.new(gemspec) do |t|
|
8
|
+
|
9
|
+
# Name of the package
|
10
|
+
t.name = gemspec.name
|
11
|
+
|
12
|
+
# Version of the package
|
13
|
+
t.version = gemspec.version
|
14
|
+
|
15
|
+
# Directory used to store the package files
|
16
|
+
t.package_dir = "pkg"
|
17
|
+
|
18
|
+
# True if a gzipped tar file (tgz) should be produced
|
19
|
+
t.need_tar = false
|
20
|
+
|
21
|
+
# True if a gzipped tar file (tar.gz) should be produced
|
22
|
+
t.need_tar_gz = false
|
23
|
+
|
24
|
+
# True if a bzip2'd tar file (tar.bz2) should be produced
|
25
|
+
t.need_tar_bz2 = false
|
26
|
+
|
27
|
+
# True if a zip file should be produced (default is false)
|
28
|
+
t.need_zip = false
|
29
|
+
|
30
|
+
# List of files to be included in the package.
|
31
|
+
t.package_files = gemspec.files
|
32
|
+
|
33
|
+
# Tar command for gzipped or bzip2ed archives.
|
34
|
+
t.tar_command = "tar"
|
35
|
+
|
36
|
+
# Zip command for zipped archives.
|
37
|
+
t.zip_command = "zip"
|
38
|
+
|
39
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :test do
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
tests = []
|
5
|
+
|
6
|
+
desc "Runs unit tests on the library itself"
|
7
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
8
|
+
t.pattern = "spec/unit/**/test_*.rb"
|
9
|
+
t.rspec_opts = ["-Ilib", "-Ispec/unit", "--color", "--backtrace", "--format=progress"]
|
10
|
+
end
|
11
|
+
tests << :unit
|
12
|
+
|
13
|
+
task :all => tests
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Runs all tests, unit then integration on examples"
|
17
|
+
task :test => :'test:all'
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bmg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bernard Lambeau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: path
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: roo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
description: Bmg is Alf's relational algebra for ruby, but much simpler and lighter
|
70
|
+
than Alf itself
|
71
|
+
email: blambeau@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.md
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/bmg.rb
|
81
|
+
- lib/bmg/operator.rb
|
82
|
+
- lib/bmg/operator/allbut.rb
|
83
|
+
- lib/bmg/operator/autosummarize.rb
|
84
|
+
- lib/bmg/operator/autowrap.rb
|
85
|
+
- lib/bmg/operator/project.rb
|
86
|
+
- lib/bmg/operator/rename.rb
|
87
|
+
- lib/bmg/reader.rb
|
88
|
+
- lib/bmg/reader/csv.rb
|
89
|
+
- lib/bmg/reader/excel.rb
|
90
|
+
- lib/bmg/relation.rb
|
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
|
+
- tasks/gem.rake
|
105
|
+
- tasks/test.rake
|
106
|
+
homepage: http://github.com/enspirit/bmg
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Bmg is Alf's successor.
|
130
|
+
test_files: []
|