namo 0.31.1 → 0.31.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5235177577fcae1dd01a8a3172fc3933e77a5483f123ba6f436bd58a6eca68e
4
- data.tar.gz: b2c023063fa95cca3f6ec38f324a116bf013339003d4051338a7c84b57251944
3
+ metadata.gz: 820a3c18db30a81cef333ad6b6bd95cd3129610d8d237a0a4f14554d23bdd2e9
4
+ data.tar.gz: 8b0c94985ae46c47e8b129eecd7fe7eba7d30f499aea917b2c9e80b1edf2ad7c
5
5
  SHA512:
6
- metadata.gz: 3278fdcba0888a5899930abb399c3cc3b1aff49d7bb27ceefc223524c4247cb4c85ca0274ba58254965229e9cec131c014a544fce61444e8d6e34221896047e5
7
- data.tar.gz: 94cdb60c0bc852b456ded744a63f8e7fda0dbf884d2ff085b0908cfb80d26f48588b4254b7d389cb68b4bce0f668d3a528ce5eeba22bd80ea4a50331c6ccb2e8
6
+ metadata.gz: a5631205eb63c196e4ba9d6b8cf5bf54807e61a462e55645e216aeb5515d767934413c226a0cb567ae0637002e6c3a80a3490c6db7c94397ae17da2c42ae8c8f
7
+ data.tar.gz: 829d09221f044a4572ff7b97bc76c3a84cd7c8ce8e9e2ee8656b2ac5c82a3753d2f793223bdf3125a0e22d925bf86e19078680b78d6dcde7077248aef7488740
data/CHANGELOG CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## 20260824
4
4
 
5
+ 0.31.2: ~ Namo#inspect: the derived: suffix names only what the rows do not carry.
6
+
7
+ 1. ~ Namo#inspect: the derived: suffix names only the derived dimensions the rendered rows do not already carry, and is omitted where they all do. A formula which raises, a parameterised one which cannot be materialised without its arguments, and any formula on a Namo with no rows to render, are named as before, being nowhere else in the output. Namo::Collection renders no rows and so names every one of its own. Namo::Row is unchanged, naming its formulae in every case.
8
+ 2. ~ README.md: the Inspection output section, and the block whose suffix goes.
9
+ 3. ~ ROADMAP.md: + 0.31.2.
10
+ 4. ~ Namo::VERSION: /0.31.1/0.31.2/
11
+
12
+
5
13
  0.31.1: ~ Namo#inspect, Namo::Row#inspect: derived dimensions render their values.
6
14
 
7
15
  1. ~ Namo#inspect: a derived dimension renders with its value, in among the stored ones, rather than being named only. Where there is no value to show it is omitted and the derived: suffix names it alone: a formula which raises, and a parameterised one which cannot be materialised without its arguments.
data/README.md CHANGED
@@ -972,7 +972,7 @@ sales[:product, :quarter, :revenue].to_h
972
972
 
973
973
  ### Inspection output
974
974
 
975
- `inspect` renders the class, the stored rows with any derived dimensions among them, and the names of those derived dimensions:
975
+ `inspect` renders the class and the stored rows, with any derived dimensions among them:
976
976
 
977
977
  ```ruby
978
978
  sales.inspect
@@ -981,18 +981,20 @@ sales.inspect
981
981
  # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150, revenue: 1500.0},
982
982
  # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40, revenue: 1000.0},
983
983
  # {product: "Gadget", quarter: "Q2", price: 25.0, quantity: 60, revenue: 1500.0}
984
- # ] derived: [:revenue]>
984
+ # ]>
985
985
  ```
986
986
 
987
987
  A name, where the Namo carries one, follows the class: `#<Namo :sales [`. A subclass reports its own name in place of `Namo`.
988
988
 
989
- A derived dimension shows its value, in among the stored ones, and the `derived:` suffix names which of the keys are computed. Where there is no value to show it is omitted rather than the rendering failing: a formula which raises, and a parameterised one which cannot be materialised without its arguments, each render nothing and are named by the suffix alone.
989
+ A derived dimension shows its value, in among the stored ones, so a computed dimension renders exactly as a stored one does — which is the claim the library makes about it. Where there is no value to show, the rendering omits it rather than failing, and the `derived:` suffix names it: a formula which raises, a parameterised one which cannot be materialised without its arguments, and any formula at all on a Namo with no rows to render.
990
+
991
+ The suffix carries only those. Where every derived dimension rendered a value it has nothing left to say and does not appear. Ask `derived_dimensions` when you want the distinction named.
990
992
 
991
993
  Evaluation is bounded by the row cap rather than by the data — at most ten rows are rendered, so at most ten evaluations per formula. A collection-scoped formula makes each of those a pass over the Namo, so inspecting a large one that carries such a formula is not free.
992
994
 
993
995
  Rows beyond `Namo::INSPECTED_ROWS` — ten — are elided with a count of the remainder, so the output stays bounded however large the data: a thousand-row Namo renders its first ten rows and then `... 990 more rows`.
994
996
 
995
- A `Row` renders itself, its derived values and its formula names, never the Namo it came from. A `Collection` renders its member names and its row count, the members being its substance and the data view derived from them.
997
+ A `Row` renders itself, its derived values and its formula names in every case, having no `derived_dimensions` of its own to be asked, and never the Namo it came from. A `Collection` renders its member names and its row count, the members being its substance and the data view derived from them.
996
998
 
997
999
  ```ruby
998
1000
  sales.first
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.31.1'
5
+ VERSION = '0.31.2'
6
6
  end
data/lib/namo.rb CHANGED
@@ -250,7 +250,8 @@ class Namo
250
250
  end
251
251
 
252
252
  def inspect
253
- "#<#{self.class}#{inspected_name}#{inspected_rows}#{inspected_derived}>"
253
+ rendered = @data.first(INSPECTED_ROWS).map{|row| [row, inspected_derivations(row)]}
254
+ "#<#{self.class}#{inspected_name}#{inspected_rows(rendered)}#{inspected_derived(rendered)}>"
254
255
  end
255
256
 
256
257
  protected
@@ -278,17 +279,13 @@ class Namo
278
279
  # The rows as they are stored, never the derived values: inspect is called
279
280
  # for every result in a console, and evaluating a formula there would cost a
280
281
  # pass over the data per access and raise whatever the formula raises.
281
- def inspected_rows
282
+ def inspected_rows(rendered)
282
283
  return ' []' if @data.empty?
283
- shown = @data.first(INSPECTED_ROWS).map{|row| " #{inspected_row(row)}"}.join(",\n")
284
+ shown = rendered.map{|row, derived| " #{row.merge(derived).inspect}"}.join(",\n")
284
285
  shown += "\n ... #{@data.length - INSPECTED_ROWS} more rows" if @data.length > INSPECTED_ROWS
285
286
  " [\n#{shown}\n]"
286
287
  end
287
288
 
288
- def inspected_row(row)
289
- row.merge(inspected_derivations(row)).inspect
290
- end
291
-
292
289
  # A derived dimension is shown with its value, in among the stored ones. A
293
290
  # formula wanting arguments has no value to show without them, and one which
294
291
  # raises has none to show either; the derived list still names both.
@@ -302,8 +299,15 @@ class Namo
302
299
  end
303
300
  end
304
301
 
305
- def inspected_derived
306
- derived_dimensions.empty? ? '' : " derived: #{derived_dimensions.inspect}"
302
+ # Only those the rows above do not already carry. A formula which raises, and a
303
+ # parameterised one which cannot be materialised without its arguments, render
304
+ # no value and would otherwise be nowhere in the output at all. A Collection
305
+ # renders no rows and so passes none, naming every one of them.
306
+ def inspected_derived(rendered = [])
307
+ unshown = derived_dimensions.reject do |dimension|
308
+ rendered.any? && rendered.all?{|_, derived| derived.key?(dimension)}
309
+ end
310
+ unshown.empty? ? '' : " derived: #{unshown.inspect}"
307
311
  end
308
312
 
309
313
  def initialize(positional_data = nil, data: [], formulae: {}, name: nil)
data/test/namo_test.rb CHANGED
@@ -3234,13 +3234,19 @@ describe Namo do
3234
3234
  it "shows a derived dimension with its value, in among the stored ones" do
3235
3235
  namo = Namo.new([{a: 1}])
3236
3236
  namo[:b] = proc{|row| row[:a] + 1}
3237
- _(namo.inspect).must_equal "#<Namo [\n {a: 1, b: 2}\n] derived: [:b]>"
3237
+ _(namo.inspect).must_equal "#<Namo [\n {a: 1, b: 2}\n]>"
3238
3238
  end
3239
3239
 
3240
3240
  it "shows a collection-scoped derived value" do
3241
3241
  namo = Namo.new([{a: 1}, {a: 2}])
3242
3242
  namo[:total] = proc{|row, namo| namo.values(:a).sum}
3243
- _(namo.inspect).must_equal "#<Namo [\n {a: 1, total: 3},\n {a: 2, total: 3}\n] derived: [:total]>"
3243
+ _(namo.inspect).must_equal "#<Namo [\n {a: 1, total: 3},\n {a: 2, total: 3}\n]>"
3244
+ end
3245
+
3246
+ it "names a derived dimension on a Namo with no rows, there being nowhere else to learn of it" do
3247
+ namo = Namo.new([])
3248
+ namo[:b] = proc{|row| row[:a] + 1}
3249
+ _(namo.inspect).must_equal "#<Namo [] derived: [:b]>"
3244
3250
  end
3245
3251
 
3246
3252
  it "names a derived dimension whose formula raises, without a value" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.1
4
+ version: 0.31.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran