object_table 0.3.4 → 0.4.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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +206 -108
- data/lib/object_table/basic_grid.rb +1 -1
- data/lib/object_table/column.rb +6 -7
- data/lib/object_table/factory.rb +46 -0
- data/lib/object_table/grouping/grid.rb +47 -0
- data/lib/object_table/grouping.rb +109 -0
- data/lib/object_table/joining.rb +71 -0
- data/lib/object_table/masked_column.rb +2 -2
- data/lib/object_table/printing.rb +69 -0
- data/lib/object_table/stacking.rb +66 -0
- data/lib/object_table/static_view.rb +2 -5
- data/lib/object_table/table_methods.rb +35 -22
- data/lib/object_table/util.rb +19 -0
- data/lib/object_table/version.rb +1 -1
- data/lib/object_table/view.rb +7 -5
- data/lib/object_table/view_methods.rb +3 -2
- data/lib/object_table.rb +8 -19
- data/object_table.gemspec +2 -0
- data/spec/object_table/column_spec.rb +2 -2
- data/spec/object_table/grouping_spec.rb +475 -0
- data/spec/object_table/static_view_spec.rb +2 -2
- data/spec/object_table/util_spec.rb +43 -0
- data/spec/object_table/view_spec.rb +6 -16
- data/spec/object_table_spec.rb +45 -3
- data/spec/subclassing_spec.rb +44 -5
- data/spec/support/joining_example.rb +171 -0
- data/spec/support/object_table_example.rb +124 -29
- data/spec/support/stacking_example.rb +111 -0
- data/spec/support/utils.rb +8 -0
- data/spec/support/view_example.rb +10 -13
- metadata +20 -12
- data/lib/object_table/group.rb +0 -10
- data/lib/object_table/grouped.rb +0 -93
- data/lib/object_table/printable.rb +0 -72
- data/lib/object_table/stacker.rb +0 -59
- data/lib/object_table/table_child.rb +0 -19
- data/spec/object_table/grouped_spec.rb +0 -351
- data/spec/support/stacker_example.rb +0 -158
@@ -1,158 +0,0 @@
|
|
1
|
-
require 'object_table'
|
2
|
-
|
3
|
-
RSpec.shared_examples 'a table stacker' do
|
4
|
-
|
5
|
-
let(:grids) do
|
6
|
-
[
|
7
|
-
ObjectTable.new(col1: [1, 2, 3], col2: 5),
|
8
|
-
ObjectTable.new(col1: 10, col2: 50),
|
9
|
-
ObjectTable.new(col2: [10, 30], col1: 15).where{col2.eq 10},
|
10
|
-
ObjectTable::BasicGrid[col2: [1, 2], col1: 3..4],
|
11
|
-
]
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:segment) { NArray.float(10, 10, 10).indgen }
|
15
|
-
|
16
|
-
let!(:grids_copy) { grids.map(&:clone) }
|
17
|
-
|
18
|
-
shared_examples 'a stacking operation' do
|
19
|
-
|
20
|
-
it 'should join the tables and grids together' do
|
21
|
-
expect(subject).to be_a described_class
|
22
|
-
expect(subject).to eql described_class.new(
|
23
|
-
col1: grids_copy.flat_map{|x| x[:col1].to_a},
|
24
|
-
col2: grids_copy.flat_map{|x| x[:col2].to_a},
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with non grids/tables' do
|
29
|
-
let(:grids){ [ObjectTable.new(col1: 10, col2: 50), 'not a table'] }
|
30
|
-
|
31
|
-
it 'should fail' do
|
32
|
-
expect{subject}.to raise_error
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with only a non-grid/table' do
|
36
|
-
let(:grids) { ['not a table'] }
|
37
|
-
|
38
|
-
it 'should fail' do
|
39
|
-
expect{subject}.to raise_error
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with extra column names' do
|
45
|
-
let(:grids){ [ObjectTable.new(col1: 10, col2: 50), ObjectTable.new(col1: 10, col2: 30, col3: 50)] }
|
46
|
-
|
47
|
-
it 'should fail' do
|
48
|
-
expect{subject}.to raise_error
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with missing column names' do
|
53
|
-
let(:grids){ [ObjectTable.new(col1: 10, col2: 50), ObjectTable.new(col1: 10)] }
|
54
|
-
|
55
|
-
it 'should fail' do
|
56
|
-
expect{subject}.to raise_error
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with empty tables' do
|
61
|
-
let(:grids) { [ ObjectTable.new(col1: [1, 2, 3], col2: 5), ObjectTable.new ] }
|
62
|
-
|
63
|
-
it 'should ignore empty tables' do
|
64
|
-
expect(subject).to eql grids[0]
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'with only empty tables' do
|
68
|
-
let(:grids) { [ObjectTable.new] * 3 }
|
69
|
-
|
70
|
-
it 'should return an empty table' do
|
71
|
-
expect(subject).to eql described_class.new
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'with tables with empty rows' do
|
77
|
-
let(:grids) { [ ObjectTable.new(col1: [1, 2, 3], col2: 5), ObjectTable.new(col1: [], col2: []) ] }
|
78
|
-
|
79
|
-
it 'should ignore empty tables' do
|
80
|
-
expect(subject).to eql grids_copy[0]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'with empty grids' do
|
85
|
-
let(:grids) { [ ObjectTable.new(col1: [1, 2, 3], col2: 5), ObjectTable::BasicGrid.new ] }
|
86
|
-
|
87
|
-
it 'should ignore empty grids' do
|
88
|
-
expect(subject).to eql grids_copy[0]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'with only narray segments' do
|
93
|
-
let(:grids) { [ObjectTable.new(col1: segment)] * 3 }
|
94
|
-
|
95
|
-
it 'should work' do
|
96
|
-
expect(subject.col1).to eql NArray.to_na(segment.to_a * 3)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'with a mixture of segment types' do
|
101
|
-
let(:grids) { [ObjectTable.new(col1: segment)] * 2 + [ObjectTable::BasicGrid[col1: segment.to_a]] * 3 }
|
102
|
-
|
103
|
-
it 'should work' do
|
104
|
-
expect(subject.col1).to eql NArray.to_na(segment.to_a * 5)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
describe '.stack' do
|
112
|
-
subject{ described_class.stack *grids }
|
113
|
-
|
114
|
-
it_behaves_like 'a stacking operation'
|
115
|
-
|
116
|
-
it 'should duplicate the contents' do
|
117
|
-
grids.each do |chunk|
|
118
|
-
expect(subject).to_not be chunk
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'with no arguments' do
|
123
|
-
let(:grids){ [] }
|
124
|
-
|
125
|
-
it 'should return an empty table' do
|
126
|
-
expect(subject).to eql described_class.new
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'with only empty grids' do
|
131
|
-
let(:grids) { [ObjectTable::BasicGrid.new] * 3 }
|
132
|
-
|
133
|
-
it 'should return an empty table' do
|
134
|
-
expect(subject).to eql described_class.new
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'with only array segments' do
|
139
|
-
let(:grids) { [ObjectTable::BasicGrid[col1: segment.to_a]] * 3 }
|
140
|
-
|
141
|
-
it 'should work' do
|
142
|
-
expect(subject.col1).to eql NArray.to_na(segment.to_a * 3)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
describe '#stack!' do
|
149
|
-
subject{ grids[0].stack! *grids[1..-1] }
|
150
|
-
it_behaves_like 'a stacking operation'
|
151
|
-
|
152
|
-
it 'should modify the table' do
|
153
|
-
expect(subject).to be grids[0]
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
end
|