namo 0.32.5 → 0.32.6
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/README.md +2 -0
- data/lib/Namo/Enumerable.rb +10 -1
- data/lib/Namo/VERSION.rb +1 -1
- data/test/namo_test.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 43fba45fc148a057ec113497f43f689b027e68c76f323f49d4590de48e7942e5
|
|
4
|
+
data.tar.gz: '02397331f3d30d460b63a0e2e1441d5820f4ca3134b25a73ba54d86fc4eaa9a6'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a26014811ea6c61e0e25c746d5f77314971554292823ddbd1ed6bca43406de1754a477b336c68d9767f534eab04717b7fc22ea434efdaadd5f4f786e2aac1ca8
|
|
7
|
+
data.tar.gz: 234bacaeb9d7daa7fb05bf70036aa90ac6599270dc1d868966ceb06d75bfc1defd41ed6e21329e93e3236911075fe81424ee196c0c3e1aa662c252f1be390ea0
|
data/README.md
CHANGED
|
@@ -1295,6 +1295,8 @@ prices.group_by(:value_score)
|
|
|
1295
1295
|
|
|
1296
1296
|
This gives a single inversion law over the whole namespace — `namo.group_by(d).as_detail(d) == namo[*namo.data_dimensions, d]` for any `d`, with the exact-original round-trip being the data-dimension instance of it. A nil-valued group produces a nil-named member, holding its rows and round-tripping like any other.
|
|
1297
1297
|
|
|
1298
|
+
`group_by` takes a dimension and no block. The block form `Enumerable#group_by` teaches is not implemented — the groups a computed key makes would have no dimension to round-trip through on `as_detail` — and it says so when called; partitioning by a computed key drops to Ruby, where `prices.entries.group_by{|row| row[:symbol]}` returns the `{key => [Row]}` hash `Enumerable#group_by` always returned.
|
|
1299
|
+
|
|
1298
1300
|
## Name
|
|
1299
1301
|
|
|
1300
1302
|
Namo: nam(ed) (dimensi)o(ns). A companion to Numo (numeric arrays for Ruby). And in Aussie culture 'o' gets added to the end of names.
|
data/lib/Namo/Enumerable.rb
CHANGED
|
@@ -69,7 +69,16 @@ class Namo
|
|
|
69
69
|
]
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
# The block form is the call Enumerable#group_by makes, and it is not
|
|
73
|
+
# implemented: the groups a computed key makes have no dimension to
|
|
74
|
+
# round-trip through on as_detail. The raise says so and names the way to
|
|
75
|
+
# partition by one, where Ruby's arity error said only that the count was
|
|
76
|
+
# wrong; a call with no dimension at all gets its own sentence.
|
|
77
|
+
def group_by(dimension = nil)
|
|
78
|
+
if block_given?
|
|
79
|
+
raise ArgumentError, 'the block form of group_by is not implemented; entries.group_by{|row| ...} partitions by a computed key'
|
|
80
|
+
end
|
|
81
|
+
raise ArgumentError, 'group_by needs a dimension' if dimension.nil?
|
|
73
82
|
collection = Collection.new
|
|
74
83
|
source = derived_dimensions.include?(dimension) ? self[*data_dimensions, dimension] : self
|
|
75
84
|
members = (
|
data/lib/Namo/VERSION.rb
CHANGED
data/test/namo_test.rb
CHANGED
|
@@ -3234,6 +3234,18 @@ describe Namo do
|
|
|
3234
3234
|
end
|
|
3235
3235
|
end
|
|
3236
3236
|
|
|
3237
|
+
context "the boundary of the call" do
|
|
3238
|
+
it "raises informatively on the block form, which is not implemented" do
|
|
3239
|
+
error = _(proc{prices.group_by{|row| row[:symbol]}}).must_raise ArgumentError
|
|
3240
|
+
_(error.message).must_match(/entries\.group_by/)
|
|
3241
|
+
end
|
|
3242
|
+
|
|
3243
|
+
it "raises informatively with no dimension at all" do
|
|
3244
|
+
error = _(proc{prices.group_by}).must_raise ArgumentError
|
|
3245
|
+
_(error.message).must_match(/dimension/)
|
|
3246
|
+
end
|
|
3247
|
+
end
|
|
3248
|
+
|
|
3237
3249
|
context "single-pass assembly" do
|
|
3238
3250
|
# Collection#<< rebuilds @data = detail.data over all members-so-far on every
|
|
3239
3251
|
# append, so appending one member per group re-materialised the data g times
|