ntable 0.1.1 → 0.1.2
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.
- data/History.rdoc +10 -0
- data/Version +1 -1
- data/lib/ntable.rb +2 -2
- data/lib/ntable/axis.rb +17 -9
- data/lib/ntable/structure.rb +75 -47
- data/lib/ntable/table.rb +24 -7
- data/test/tc_axes.rb +20 -20
- data/test/tc_structure.rb +20 -20
- metadata +2 -2
data/History.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.1.2 / 2012-09-09
|
2
|
+
|
3
|
+
I took a long look at ntable's interface, and the usage patterns of my own personal projects that depended on it, and decided some simplification was needed.
|
4
|
+
|
5
|
+
* INCOMPATIBLE CHANGE: Renamed the "index_to_label" and "label_to_index" methods on axis objects to "label" and "index", respectively.
|
6
|
+
* INCOMPATIBLE CHANGE: Renamed the "axis", "index", and "name" methods on AxisInfo to "axis_object", "axis_index", and "axis_name", respectively.
|
7
|
+
* Added "index", "label", and "size" methods to AxisInfo, delegating to the underlying axis object. This means AxisInfo is now effectively a proxy for the axis implementation, which should normally no longer need to be accessed.
|
8
|
+
* INCOMPATIBLE CHANGE: Renamed the "axis_info" and "all_axis_info" methods of Structure to "axis" and "all_axes", respectively.
|
9
|
+
* The "axis" and "all_axes" methods of Structure are now exposed on Table, so you should not need to access the structure too often.
|
10
|
+
|
1
11
|
=== 0.1.1 / 2012-09-07
|
2
12
|
|
3
13
|
* The "preferred" construction methods are now module methods on ::NTable.
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/ntable.rb
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
# such a table with 100 rows and two columns could be created like this:
|
59
59
|
#
|
60
60
|
# table = NTable.structure(NTable::IndexedAxis.new(100)).
|
61
|
-
# add(NTable::LabeledAxis(:name, :address)).
|
61
|
+
# add(NTable::LabeledAxis.new(:name, :address)).
|
62
62
|
# create
|
63
63
|
#
|
64
64
|
# You can then look up individual cells like this:
|
@@ -68,7 +68,7 @@
|
|
68
68
|
# Axes can be given names as well:
|
69
69
|
#
|
70
70
|
# table = NTable.structure(NTable::IndexedAxis.new(100), :row).
|
71
|
-
# add(NTable::LabeledAxis(:name, :address), :col).
|
71
|
+
# add(NTable::LabeledAxis.new(:name, :address), :col).
|
72
72
|
# create
|
73
73
|
#
|
74
74
|
# Then you can specify the axes by name when you look up:
|
data/lib/ntable/axis.rb
CHANGED
@@ -49,15 +49,23 @@ module NTable
|
|
49
49
|
class EmptyAxis
|
50
50
|
|
51
51
|
|
52
|
+
# Axis objects must implement an equality check.
|
53
|
+
|
52
54
|
def eql?(obj_)
|
53
55
|
obj_.is_a?(EmptyAxis)
|
54
56
|
end
|
55
57
|
alias_method :==, :eql?
|
56
58
|
|
59
|
+
|
60
|
+
# Axis objects must implement a hash
|
61
|
+
|
57
62
|
def hash
|
58
63
|
self.class.hash
|
59
64
|
end
|
60
65
|
|
66
|
+
|
67
|
+
# Axis methods should implement display methods for debugging.
|
68
|
+
|
61
69
|
def inspect
|
62
70
|
"#<#{self.class}:0x#{object_id.to_s(16)}>"
|
63
71
|
end
|
@@ -75,7 +83,7 @@ module NTable
|
|
75
83
|
# Given a label object, return the corresponding 0-based integer index.
|
76
84
|
# Returns nil if the label is not recognized.
|
77
85
|
|
78
|
-
def
|
86
|
+
def index(label_)
|
79
87
|
nil
|
80
88
|
end
|
81
89
|
|
@@ -84,7 +92,7 @@ module NTable
|
|
84
92
|
# Returns nil if the index is out of bounds (i.e. is less than 0 or
|
85
93
|
# greater than or equal to size.)
|
86
94
|
|
87
|
-
def
|
95
|
+
def label(index_)
|
88
96
|
nil
|
89
97
|
end
|
90
98
|
|
@@ -144,11 +152,11 @@ module NTable
|
|
144
152
|
attr_reader :size
|
145
153
|
|
146
154
|
|
147
|
-
def
|
155
|
+
def index(label_)
|
148
156
|
@h[label_.to_s]
|
149
157
|
end
|
150
158
|
|
151
|
-
def
|
159
|
+
def label(index_)
|
152
160
|
@a[index_]
|
153
161
|
end
|
154
162
|
|
@@ -186,7 +194,7 @@ module NTable
|
|
186
194
|
alias_method :==, :eql?
|
187
195
|
|
188
196
|
def hash
|
189
|
-
@size.hash
|
197
|
+
@size.hash ^ @start.hash
|
190
198
|
end
|
191
199
|
|
192
200
|
def inspect
|
@@ -199,11 +207,11 @@ module NTable
|
|
199
207
|
attr_reader :start
|
200
208
|
|
201
209
|
|
202
|
-
def
|
210
|
+
def index(label_)
|
203
211
|
label_ >= @start && label_ < @size + @start ? label_ - @start : nil
|
204
212
|
end
|
205
213
|
|
206
|
-
def
|
214
|
+
def label(index_)
|
207
215
|
index_ >= 0 && index_ < @size ? index_ + @start : nil
|
208
216
|
end
|
209
217
|
|
@@ -258,11 +266,11 @@ module NTable
|
|
258
266
|
attr_reader :size
|
259
267
|
|
260
268
|
|
261
|
-
def
|
269
|
+
def index(label_)
|
262
270
|
@h[label_]
|
263
271
|
end
|
264
272
|
|
265
|
-
def
|
273
|
+
def label(index_)
|
266
274
|
@a[index_]
|
267
275
|
end
|
268
276
|
|
data/lib/ntable/structure.rb
CHANGED
@@ -61,39 +61,67 @@ module NTable
|
|
61
61
|
|
62
62
|
# A data structure that provides information about a particular
|
63
63
|
# axis/dimension in a Structure. It provides access to the axis
|
64
|
-
#
|
64
|
+
# object, as well as the axis's name (if any) and 0-based index
|
65
65
|
# into the list of axes. You should never need to create an
|
66
|
-
# AxisInfo yourself, but you can obtain one from Structure#
|
66
|
+
# AxisInfo yourself, but you can obtain one from Structure#axis.
|
67
67
|
|
68
|
-
class AxisInfo
|
68
|
+
class AxisInfo
|
69
69
|
|
70
70
|
def initialize(axis_, index_, name_, step_=nil) # :nodoc:
|
71
|
-
@
|
72
|
-
@
|
73
|
-
@
|
71
|
+
@axis_object = axis_
|
72
|
+
@axis_index = index_
|
73
|
+
@axis_name = name_
|
74
74
|
@step = step_
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
# The underlying axis implementation
|
79
|
+
attr_reader :axis_object
|
80
|
+
|
79
81
|
# The 0-based index of this axis in the structure. i.e. the first,
|
80
|
-
# most major axis has
|
81
|
-
attr_reader :
|
82
|
+
# most major axis has number 0.
|
83
|
+
attr_reader :axis_index
|
84
|
+
|
82
85
|
# The name of this axis in the structure as a string, or nil for
|
83
86
|
# no name.
|
84
|
-
attr_reader :
|
87
|
+
attr_reader :axis_name
|
85
88
|
|
86
89
|
attr_reader :step # :nodoc:
|
87
90
|
|
88
91
|
|
92
|
+
# Given a label object, return the corresponding 0-based integer index.
|
93
|
+
# Returns nil if the label is not recognized.
|
94
|
+
|
95
|
+
def index(label_)
|
96
|
+
@axis_object.index(label_)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Given a 0-based integer index, return the corresponding label object.
|
101
|
+
# Returns nil if the index is out of bounds (i.e. is less than 0 or
|
102
|
+
# greater than or equal to size.)
|
103
|
+
|
104
|
+
def label(index_)
|
105
|
+
@axis_object.label(index_)
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# Return the number of rows along this axis.
|
110
|
+
# An empty axis will return 0.
|
111
|
+
|
112
|
+
def size
|
113
|
+
@axis_object.size
|
114
|
+
end
|
115
|
+
|
116
|
+
|
89
117
|
def eql?(obj_) # :nodoc:
|
90
|
-
obj_.is_a?(AxisInfo) &&
|
118
|
+
obj_.is_a?(AxisInfo) && @axis_object.eql?(obj_.axis_object) && @axis_name.eql?(obj_.axis_name)
|
91
119
|
end
|
92
120
|
alias_method :==, :eql? # :nodoc:
|
93
121
|
|
94
122
|
|
95
123
|
def _set_axis(axis_) # :nodoc:
|
96
|
-
@
|
124
|
+
@axis_object = axis_
|
97
125
|
end
|
98
126
|
|
99
127
|
def _set_step(step_) # :nodoc:
|
@@ -101,7 +129,7 @@ module NTable
|
|
101
129
|
end
|
102
130
|
|
103
131
|
def _dec_index # :nodoc:
|
104
|
-
@
|
132
|
+
@axis_index -= 1
|
105
133
|
end
|
106
134
|
|
107
135
|
end
|
@@ -132,8 +160,8 @@ module NTable
|
|
132
160
|
# axis may be provided by name or index.
|
133
161
|
|
134
162
|
def coord(axis_)
|
135
|
-
ainfo_ = @structure.
|
136
|
-
ainfo_ ? _coords[ainfo_.
|
163
|
+
ainfo_ = @structure.axis(axis_)
|
164
|
+
ainfo_ ? _coords[ainfo_.axis_index] : nil
|
137
165
|
end
|
138
166
|
alias_method :[], :coord
|
139
167
|
|
@@ -194,7 +222,7 @@ module NTable
|
|
194
222
|
other_.instance_variable_get(:@indexes).each do |ai_|
|
195
223
|
ai_ = ai_.dup
|
196
224
|
@indexes << ai_
|
197
|
-
if (name_ = ai_.
|
225
|
+
if (name_ = ai_.axis_name)
|
198
226
|
@names[name_] = ai_
|
199
227
|
end
|
200
228
|
end
|
@@ -207,7 +235,7 @@ module NTable
|
|
207
235
|
|
208
236
|
def unlocked_copy
|
209
237
|
copy_ = Structure.new
|
210
|
-
@indexes.each{ |ai_| copy_.add(ai_.
|
238
|
+
@indexes.each{ |ai_| copy_.add(ai_.axis_object, ai_.axis_name) }
|
211
239
|
copy_
|
212
240
|
end
|
213
241
|
|
@@ -239,7 +267,7 @@ module NTable
|
|
239
267
|
if rhs_indexes_.size == @indexes.size
|
240
268
|
rhs_indexes_.each_with_index do |rhs_ai_, i_|
|
241
269
|
lhs_ai_ = @indexes[i_]
|
242
|
-
return false unless lhs_ai_.
|
270
|
+
return false unless lhs_ai_.axis_object == rhs_ai_.axis_object && lhs_ai_.axis_name == rhs_ai_.axis_name
|
243
271
|
end
|
244
272
|
return true
|
245
273
|
end
|
@@ -271,17 +299,17 @@ module NTable
|
|
271
299
|
|
272
300
|
def remove(axis_)
|
273
301
|
raise StructureStateError, "Structure locked" if @locked
|
274
|
-
ainfo_ =
|
302
|
+
ainfo_ = axis(axis_)
|
275
303
|
unless ainfo_
|
276
304
|
raise UnknownAxisError, "Unknown axis: #{axis_.inspect}"
|
277
305
|
end
|
278
|
-
index_ = ainfo_.
|
279
|
-
@names.delete(ainfo_.
|
306
|
+
index_ = ainfo_.axis_index
|
307
|
+
@names.delete(ainfo_.axis_name)
|
280
308
|
@indexes.delete_at(index_)
|
281
309
|
@indexes[index_..-1].each{ |ai_| ai_._dec_index }
|
282
|
-
size_ = ainfo_.
|
310
|
+
size_ = ainfo_.size
|
283
311
|
if size_ == 0
|
284
|
-
@size = @indexes.inject(1){ |s_, ai_| s_ * ai_.
|
312
|
+
@size = @indexes.inject(1){ |s_, ai_| s_ * ai_.size }
|
285
313
|
else
|
286
314
|
@size /= size_
|
287
315
|
end
|
@@ -299,15 +327,15 @@ module NTable
|
|
299
327
|
|
300
328
|
def replace(axis_, naxis_=nil)
|
301
329
|
raise StructureStateError, "Structure locked" if @locked
|
302
|
-
ainfo_ =
|
330
|
+
ainfo_ = axis(axis_)
|
303
331
|
unless ainfo_
|
304
332
|
raise UnknownAxisError, "Unknown axis: #{axis_.inspect}"
|
305
333
|
end
|
306
|
-
osize_ = ainfo_.
|
334
|
+
osize_ = ainfo_.size
|
307
335
|
naxis_ ||= yield(ainfo_)
|
308
336
|
ainfo_._set_axis(naxis_)
|
309
337
|
if osize_ == 0
|
310
|
-
@size = @indexes.inject(1){ |size_, ai_| size_ * ai_.
|
338
|
+
@size = @indexes.inject(1){ |size_, ai_| size_ * ai_.size }
|
311
339
|
else
|
312
340
|
@size = @size / osize_ * naxis_.size
|
313
341
|
end
|
@@ -341,7 +369,7 @@ module NTable
|
|
341
369
|
# Returns an array of AxisInfo objects representing all the axes
|
342
370
|
# of this structure.
|
343
371
|
|
344
|
-
def
|
372
|
+
def all_axes
|
345
373
|
@indexes.dup
|
346
374
|
end
|
347
375
|
|
@@ -350,7 +378,7 @@ module NTable
|
|
350
378
|
# must be specified by 0-based index or by name string. Returns nil
|
351
379
|
# if there is no such axis.
|
352
380
|
|
353
|
-
def
|
381
|
+
def axis(axis_)
|
354
382
|
case axis_
|
355
383
|
when ::Integer
|
356
384
|
@indexes[axis_]
|
@@ -370,7 +398,7 @@ module NTable
|
|
370
398
|
if @size > 0
|
371
399
|
s_ = @size
|
372
400
|
@indexes.each do |ainfo_|
|
373
|
-
s_ /= ainfo_.
|
401
|
+
s_ /= ainfo_.size
|
374
402
|
ainfo_._set_step(s_)
|
375
403
|
end
|
376
404
|
end
|
@@ -436,8 +464,8 @@ module NTable
|
|
436
464
|
|
437
465
|
def to_json_array
|
438
466
|
@indexes.map do |ai_|
|
439
|
-
name_ = ai_.
|
440
|
-
axis_ = ai_.
|
467
|
+
name_ = ai_.axis_name
|
468
|
+
axis_ = ai_.axis_object
|
441
469
|
type_ = axis_.class.name
|
442
470
|
if type_ =~ /^NTable::(\w+)Axis$/
|
443
471
|
type_ = $1
|
@@ -499,11 +527,11 @@ module NTable
|
|
499
527
|
names_ = {}
|
500
528
|
size_ = 1
|
501
529
|
@indexes.each do |ainfo_|
|
502
|
-
if axes_.include?(ainfo_.
|
503
|
-
nainfo_ = AxisInfo.new(ainfo_.
|
530
|
+
if axes_.include?(ainfo_.axis_index) == bool_
|
531
|
+
nainfo_ = AxisInfo.new(ainfo_.axis_object, indexes_.size, ainfo_.axis_name, ainfo_.step)
|
504
532
|
indexes_ << nainfo_
|
505
|
-
names_[ainfo_.
|
506
|
-
size_ *= ainfo_.
|
533
|
+
names_[ainfo_.axis_name] = nainfo_
|
534
|
+
size_ *= ainfo_.size
|
507
535
|
end
|
508
536
|
end
|
509
537
|
sub_.instance_variable_set(:@indexes, indexes_)
|
@@ -522,8 +550,8 @@ module NTable
|
|
522
550
|
when ::Hash
|
523
551
|
offset_ = 0
|
524
552
|
arg_.each do |k_, v_|
|
525
|
-
if (ainfo_ =
|
526
|
-
index_ = ainfo_.
|
553
|
+
if (ainfo_ = axis(k_))
|
554
|
+
index_ = ainfo_.index(v_)
|
527
555
|
return nil unless index_
|
528
556
|
offset_ += ainfo_.step * index_
|
529
557
|
else
|
@@ -535,7 +563,7 @@ module NTable
|
|
535
563
|
offset_ = 0
|
536
564
|
arg_.each_with_index do |v_, i_|
|
537
565
|
if (ainfo_ = @indexes[i_])
|
538
|
-
index_ = ainfo_.
|
566
|
+
index_ = ainfo_.index(v_)
|
539
567
|
return nil unless index_
|
540
568
|
offset_ += ainfo_.step * index_
|
541
569
|
else
|
@@ -556,16 +584,16 @@ module NTable
|
|
556
584
|
case arg_
|
557
585
|
when ::Hash
|
558
586
|
arg_.each do |k_, v_|
|
559
|
-
if (ainfo_ =
|
560
|
-
val_ = ainfo_.
|
561
|
-
vec_[ainfo_.
|
587
|
+
if (ainfo_ = axis(k_))
|
588
|
+
val_ = ainfo_.index(v_)
|
589
|
+
vec_[ainfo_.axis_index] = val_ if val_
|
562
590
|
end
|
563
591
|
end
|
564
592
|
vec_
|
565
593
|
when ::Array
|
566
594
|
arg_.each_with_index do |v_, i_|
|
567
595
|
if (ainfo_ = @indexes[i_])
|
568
|
-
val_ = ainfo_.
|
596
|
+
val_ = ainfo_.index(v_)
|
569
597
|
vec_[i_] = val_ if val_
|
570
598
|
end
|
571
599
|
end
|
@@ -587,7 +615,7 @@ module NTable
|
|
587
615
|
|
588
616
|
def _compute_coords_for_vector(vector_) # :nodoc:
|
589
617
|
vector_.map.with_index do |v_, i_|
|
590
|
-
@indexes[i_].
|
618
|
+
@indexes[i_].label(v_)
|
591
619
|
end
|
592
620
|
end
|
593
621
|
|
@@ -596,7 +624,7 @@ module NTable
|
|
596
624
|
(vector_.size - 1).downto(-1) do |i_|
|
597
625
|
return true if i_ < 0
|
598
626
|
v_ = vector_[i_] + 1
|
599
|
-
if v_ >= @indexes[i_].
|
627
|
+
if v_ >= @indexes[i_].size
|
600
628
|
vector_[i_] = 0
|
601
629
|
else
|
602
630
|
vector_[i_] = v_
|
@@ -612,7 +640,7 @@ module NTable
|
|
612
640
|
return true if i_ < 0
|
613
641
|
v_ = vector_[i_] - 1
|
614
642
|
if v_ < 0
|
615
|
-
vector_[i_] = @indexes[i_].
|
643
|
+
vector_[i_] = @indexes[i_].size - 1
|
616
644
|
else
|
617
645
|
vector_[i_] = v_
|
618
646
|
break
|
@@ -627,7 +655,7 @@ module NTable
|
|
627
655
|
@indexes.map do |ainfo_|
|
628
656
|
i_ = offset_ / ainfo_.step
|
629
657
|
offset_ -= ainfo_.step * i_
|
630
|
-
ainfo_.
|
658
|
+
ainfo_.label(i_)
|
631
659
|
end
|
632
660
|
end
|
633
661
|
|
data/lib/ntable/table.rb
CHANGED
@@ -161,6 +161,23 @@ module NTable
|
|
161
161
|
end
|
162
162
|
|
163
163
|
|
164
|
+
# Returns the AxisInfo object representing the given axis. The axis
|
165
|
+
# must be specified by 0-based index or by name string. Returns nil
|
166
|
+
# if there is no such axis.
|
167
|
+
|
168
|
+
def axis(axis_)
|
169
|
+
@structure.axis(axis_)
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
# Returns an array of AxisInfo objects representing all the axes
|
174
|
+
# of the structure of this table.
|
175
|
+
|
176
|
+
def all_axes
|
177
|
+
@structure.all_axes
|
178
|
+
end
|
179
|
+
|
180
|
+
|
164
181
|
# Return the parent of this table. A table with a parent shares the
|
165
182
|
# parent's data, and cannot have its data modified directly. Instead,
|
166
183
|
# if the parent table is modified, the changes are reflected in the
|
@@ -473,8 +490,8 @@ module NTable
|
|
473
490
|
axes_ = axes_.flatten
|
474
491
|
axis_indexes_ = []
|
475
492
|
axes_.each do |a_|
|
476
|
-
if (ainfo_ = @structure.
|
477
|
-
axis_indexes_ << ainfo_.
|
493
|
+
if (ainfo_ = @structure.axis(a_))
|
494
|
+
axis_indexes_ << ainfo_.axis_index
|
478
495
|
else
|
479
496
|
raise UnknownAxisError, "Unknown axis: #{a_.inspect}"
|
480
497
|
end
|
@@ -523,10 +540,10 @@ module NTable
|
|
523
540
|
offset_ = @offset
|
524
541
|
select_set_ = {}
|
525
542
|
hash_.each do |k_, v_|
|
526
|
-
if (ainfo_ = @structure.
|
527
|
-
aindex_ = ainfo_.
|
543
|
+
if (ainfo_ = @structure.axis(k_))
|
544
|
+
aindex_ = ainfo_.axis_index
|
528
545
|
unless select_set_.include?(aindex_)
|
529
|
-
lindex_ = ainfo_.
|
546
|
+
lindex_ = ainfo_.index(v_)
|
530
547
|
if lindex_
|
531
548
|
offset_ += ainfo_.step * lindex_
|
532
549
|
select_set_[aindex_] = true
|
@@ -582,7 +599,7 @@ module NTable
|
|
582
599
|
def _to_nested_obj(aidx_, vec_, opts_) # :nodoc:
|
583
600
|
exclude_ = opts_.include?(:exclude_value)
|
584
601
|
exclude_value_ = opts_[:exclude_value] if exclude_
|
585
|
-
axis_ = @structure.
|
602
|
+
axis_ = @structure.axis(aidx_).axis_object
|
586
603
|
result_ = IndexedAxis === axis_ ? [] : {}
|
587
604
|
(0...axis_.size).map do |i_|
|
588
605
|
vec_[aidx_] = i_
|
@@ -592,7 +609,7 @@ module NTable
|
|
592
609
|
_to_nested_obj(aidx_ + 1, vec_, opts_)
|
593
610
|
end
|
594
611
|
if !exclude_ || !val_.eql?(exclude_value_)
|
595
|
-
result_[axis_.
|
612
|
+
result_[axis_.label(i_)] = val_
|
596
613
|
end
|
597
614
|
end
|
598
615
|
result_
|
data/test/tc_axes.rb
CHANGED
@@ -52,18 +52,18 @@ module NTable
|
|
52
52
|
|
53
53
|
def test_labeled_axis_label_to_index
|
54
54
|
axis_ = LabeledAxis.new([:one, :two])
|
55
|
-
assert_equal(0, axis_.
|
56
|
-
assert_equal(1, axis_.
|
57
|
-
assert_equal(0, axis_.
|
58
|
-
assert_nil(axis_.
|
55
|
+
assert_equal(0, axis_.index(:one))
|
56
|
+
assert_equal(1, axis_.index(:two))
|
57
|
+
assert_equal(0, axis_.index('one'))
|
58
|
+
assert_nil(axis_.index(:three))
|
59
59
|
end
|
60
60
|
|
61
61
|
|
62
62
|
def test_labeled_axis_index_to_label
|
63
63
|
axis_ = LabeledAxis.new([:one, :two])
|
64
|
-
assert_equal('one', axis_.
|
65
|
-
assert_equal('two', axis_.
|
66
|
-
assert_nil(axis_.
|
64
|
+
assert_equal('one', axis_.label(0))
|
65
|
+
assert_equal('two', axis_.label(1))
|
66
|
+
assert_nil(axis_.label(2))
|
67
67
|
end
|
68
68
|
|
69
69
|
|
@@ -90,18 +90,18 @@ module NTable
|
|
90
90
|
|
91
91
|
def test_object_axis_label_to_index
|
92
92
|
axis_ = ObjectAxis.new([:one, :two])
|
93
|
-
assert_equal(0, axis_.
|
94
|
-
assert_equal(1, axis_.
|
95
|
-
assert_nil(axis_.
|
96
|
-
assert_nil(axis_.
|
93
|
+
assert_equal(0, axis_.index(:one))
|
94
|
+
assert_equal(1, axis_.index(:two))
|
95
|
+
assert_nil(axis_.index('one'))
|
96
|
+
assert_nil(axis_.index(:three))
|
97
97
|
end
|
98
98
|
|
99
99
|
|
100
100
|
def test_object_axis_index_to_label
|
101
101
|
axis_ = ObjectAxis.new([:one, :two])
|
102
|
-
assert_equal(:one, axis_.
|
103
|
-
assert_equal(:two, axis_.
|
104
|
-
assert_nil(axis_.
|
102
|
+
assert_equal(:one, axis_.label(0))
|
103
|
+
assert_equal(:two, axis_.label(1))
|
104
|
+
assert_nil(axis_.label(2))
|
105
105
|
end
|
106
106
|
|
107
107
|
|
@@ -128,17 +128,17 @@ module NTable
|
|
128
128
|
|
129
129
|
def test_indexed_axis_label_to_index
|
130
130
|
axis_ = IndexedAxis.new(2, 4)
|
131
|
-
assert_equal(0, axis_.
|
132
|
-
assert_equal(1, axis_.
|
133
|
-
assert_nil(axis_.
|
131
|
+
assert_equal(0, axis_.index(4))
|
132
|
+
assert_equal(1, axis_.index(5))
|
133
|
+
assert_nil(axis_.index(3))
|
134
134
|
end
|
135
135
|
|
136
136
|
|
137
137
|
def test_indexed_axis_index_to_label
|
138
138
|
axis_ = IndexedAxis.new(2, 4)
|
139
|
-
assert_equal(4, axis_.
|
140
|
-
assert_equal(5, axis_.
|
141
|
-
assert_nil(axis_.
|
139
|
+
assert_equal(4, axis_.label(0))
|
140
|
+
assert_equal(5, axis_.label(1))
|
141
|
+
assert_nil(axis_.label(2))
|
142
142
|
end
|
143
143
|
|
144
144
|
|
data/test/tc_structure.rb
CHANGED
@@ -67,10 +67,10 @@ module NTable
|
|
67
67
|
def test_add_single_axis
|
68
68
|
s_ = Structure.new
|
69
69
|
s_.add(@labeled1, :first)
|
70
|
-
assert_equal(@labeled1, s_.
|
71
|
-
assert_equal(@labeled1, s_.
|
72
|
-
assert_equal(0, s_.
|
73
|
-
assert_equal('first', s_.
|
70
|
+
assert_equal(@labeled1, s_.axis(0).axis_object)
|
71
|
+
assert_equal(@labeled1, s_.axis(:first).axis_object)
|
72
|
+
assert_equal(0, s_.axis(:first).axis_index)
|
73
|
+
assert_equal('first', s_.axis(0).axis_name)
|
74
74
|
end
|
75
75
|
|
76
76
|
|
@@ -79,16 +79,16 @@ module NTable
|
|
79
79
|
s_.add(@labeled1, :first)
|
80
80
|
s_.add(@indexed1, :second)
|
81
81
|
s_.add(@indexed1)
|
82
|
-
assert_equal(@labeled1, s_.
|
83
|
-
assert_equal(@labeled1, s_.
|
84
|
-
assert_equal(0, s_.
|
85
|
-
assert_equal('first', s_.
|
86
|
-
assert_equal(@indexed1, s_.
|
87
|
-
assert_equal(@indexed1, s_.
|
88
|
-
assert_equal(1, s_.
|
89
|
-
assert_equal('second', s_.
|
90
|
-
assert_equal(@indexed1, s_.
|
91
|
-
assert_nil(s_.
|
82
|
+
assert_equal(@labeled1, s_.axis(0).axis_object)
|
83
|
+
assert_equal(@labeled1, s_.axis(:first).axis_object)
|
84
|
+
assert_equal(0, s_.axis(:first).axis_index)
|
85
|
+
assert_equal('first', s_.axis(0).axis_name)
|
86
|
+
assert_equal(@indexed1, s_.axis(1).axis_object)
|
87
|
+
assert_equal(@indexed1, s_.axis(:second).axis_object)
|
88
|
+
assert_equal(1, s_.axis(:second).axis_index)
|
89
|
+
assert_equal('second', s_.axis(1).axis_name)
|
90
|
+
assert_equal(@indexed1, s_.axis(2).axis_object)
|
91
|
+
assert_nil(s_.axis(2).axis_name)
|
92
92
|
end
|
93
93
|
|
94
94
|
|
@@ -98,12 +98,12 @@ module NTable
|
|
98
98
|
s_.add(@indexed1, :second)
|
99
99
|
s_.remove(:first)
|
100
100
|
assert_equal(1, s_.dim)
|
101
|
-
assert_equal(@indexed1, s_.
|
102
|
-
assert_equal(@indexed1, s_.
|
103
|
-
assert_equal(0, s_.
|
104
|
-
assert_equal('second', s_.
|
105
|
-
assert_nil(s_.
|
106
|
-
assert_nil(s_.
|
101
|
+
assert_equal(@indexed1, s_.axis(0).axis_object)
|
102
|
+
assert_equal(@indexed1, s_.axis(:second).axis_object)
|
103
|
+
assert_equal(0, s_.axis(:second).axis_index)
|
104
|
+
assert_equal('second', s_.axis(0).axis_name)
|
105
|
+
assert_nil(s_.axis(1))
|
106
|
+
assert_nil(s_.axis(:first))
|
107
107
|
end
|
108
108
|
|
109
109
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: NTable provides a convenient data structure for storing n-dimensional
|
15
15
|
tabular data. It works with zero-dimensional scalar values, arrays, tables, and
|