namo 0.30.0 → 0.31.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f9ea9ed29bd86c309865e0c49d03122b7fa50460e34fd7a42a9a273bb220c0
4
- data.tar.gz: 99d5e8191c3458b498c6fe297c2af8b94d8bb73aced942d9f3da67af94ace454
3
+ metadata.gz: 1241332321c6f9d7643932d1b53949bfb12eb8596b1e388c206a9fad705efaf7
4
+ data.tar.gz: 00c558afd1fe979599820a39539f3216b496557a69f94229a59fc45c48cfd062
5
5
  SHA512:
6
- metadata.gz: 9e4aca2b13be76dc10a2fcf3eb7122045e600b1ed2410c2f6e82554c7dfc679249bf714fc52939fd4ee058fa6925b1958935bd91281dbf67f48634aec4cd4ea9
7
- data.tar.gz: d3432cb0f092521adb1e2f60dccbc5b37aff2e4f91511189300b0693d374124e76cf1fde57d64709606ea504aae5db85d9c47e7aba99efcfdfa68b6fcbc38eef
6
+ metadata.gz: 74b61473e59179fcd559d52eb98435ab9127499c17403174c1505f5076d1c6d2dd1f829ea8a69403da948709d047d42603bb1fd6bc32205bfb1bb3b0459d47c8
7
+ data.tar.gz: c9690afd20a5ab0de834d9dcca3b2a310e4da3e4811b0a29545e60290f1cb62f7571e8c177bacd405b380e8bfe6f78358a075c9c2eb5a4519654843c90ddaf5a
data/CHANGELOG CHANGED
@@ -1,5 +1,26 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 20260822
4
+
5
+ 0.31.0: + Namo#inspect, Namo::Collection#inspect, Namo::Row#inspect, and Namo::Formulae#inspect.
6
+
7
+ 1. + Namo#inspect: the class, the name where there is one, the stored rows, and the derived dimension names — the form the README has shown since 0.0.0 and the code has never produced. Rows beyond Namo::INSPECTED_ROWS are elided with a count of what is left, so the output no longer grows with the data.
8
+ 2. + Namo::Row#inspect: the row and its formula names. It had been rendering @namo, so asking a 1,000-row Namo for one row emitted more output than inspecting the whole Namo.
9
+ 3. + Namo::Collection#inspect: the member names and the row count, the members being the substance and the data view derived from them.
10
+ 4. + Namo::Formulae#inspect: the formula names, never the callables.
11
+ 5. + README.md: an Inspection output section, covering the rendered form, the naming of derived dimensions, and the row cap.
12
+ 6. ~ README.md: the inspect-output blocks requoted from single to double quotes, as Hash#inspect emits, and the two projections that carry formulae given their derived: suffix. The blocks had been hand-written before there was an inspect to copy from.
13
+ 7. ~ Namo::VERSION: /0.30.1/0.31.0/
14
+
15
+
16
+ ## 20260819
17
+
18
+ 0.30.1: ~ namo.gemspec: spec.files reordered, the globs first.
19
+
20
+ 1. ~ namo.gemspec: spec.files reordered, the two Dir globs first and the loose files alphabetically after them, as moby and measurand have it. The globs are what the gem is and the rest is paperwork, so adding a file to the paperwork now never disturbs them. This gemspec had been pinned first with the globs last, which http shared and impuri left at its 0.12.1. The same 21 files ship, in the same gem; only the order in the source changes.
21
+ 2. ~ Namo::VERSION: /0.30.0/0.30.1/
22
+
23
+
3
24
  ## 20260715
4
25
 
5
26
  0.30.0: Assemble Collection objects in a single pass when doing Namo::Enumerable#group_by.
data/README.md CHANGED
@@ -66,42 +66,42 @@ Select by named dimension using keyword arguments:
66
66
  # Single value
67
67
  sales[product: 'Widget']
68
68
  # => #<Namo [
69
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
70
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
69
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
70
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
71
71
  # ]>
72
72
 
73
73
  # Multiple dimensions
74
74
  sales[product: 'Widget', quarter: 'Q1']
75
75
  # => #<Namo [
76
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100}
76
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100}
77
77
  # ]>
78
78
 
79
79
  # Range
80
80
  sales[price: 10.0..20.0]
81
81
  # => #<Namo [
82
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
83
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
82
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
83
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
84
84
  # ]>
85
85
 
86
86
  # Array of values
87
87
  sales[quarter: ['Q1']]
88
88
  # => #<Namo [
89
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
90
- # {product: 'Gadget', quarter: 'Q1', price: 25.0, quantity: 40}
89
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
90
+ # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40}
91
91
  # ]>
92
92
 
93
93
  # Proc predicate
94
94
  sales[price: ->(v){v < 20.0}]
95
95
  # => #<Namo [
96
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
97
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
96
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
97
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
98
98
  # ]>
99
99
 
100
100
  # Regex predicate
101
101
  sales[product: /^W/]
102
102
  # => #<Namo [
103
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
104
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
103
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
104
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
105
105
  # ]>
106
106
  ```
107
107
 
@@ -110,7 +110,7 @@ Procs receive the dimension value and select the row when they return truthy. Th
110
110
  ```ruby
111
111
  sales[price: ->(v){v < 20.0}, quantity: ->(v){v > 100}]
112
112
  # => #<Namo [
113
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
113
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
114
114
  # ]>
115
115
  ```
116
116
 
@@ -131,10 +131,10 @@ Project to specific dimensions:
131
131
  ```ruby
132
132
  sales[:product, :price]
133
133
  # => #<Namo [
134
- # {product: 'Widget', price: 10.0},
135
- # {product: 'Widget', price: 10.0},
136
- # {product: 'Gadget', price: 25.0},
137
- # {product: 'Gadget', price: 25.0}
134
+ # {product: "Widget", price: 10.0},
135
+ # {product: "Widget", price: 10.0},
136
+ # {product: "Gadget", price: 25.0},
137
+ # {product: "Gadget", price: 25.0}
138
138
  # ]>
139
139
  ```
140
140
 
@@ -143,8 +143,8 @@ Selection and projection can be chained:
143
143
  ```ruby
144
144
  sales[product: 'Widget'][:quarter, :price]
145
145
  # => #<Namo [
146
- # {quarter: 'Q1', price: 10.0},
147
- # {quarter: 'Q2', price: 10.0}
146
+ # {quarter: "Q1", price: 10.0},
147
+ # {quarter: "Q2", price: 10.0}
148
148
  # ]>
149
149
  ```
150
150
 
@@ -153,8 +153,8 @@ Or combined in a single call (names before selectors):
153
153
  ```ruby
154
154
  sales[:quarter, :price, product: 'Widget']
155
155
  # => #<Namo [
156
- # {quarter: 'Q1', price: 10.0},
157
- # {quarter: 'Q2', price: 10.0}
156
+ # {quarter: "Q1", price: 10.0},
157
+ # {quarter: "Q2", price: 10.0}
158
158
  # ]>
159
159
  ```
160
160
 
@@ -165,10 +165,10 @@ Contraction is the complement of projection. Projection says "keep these dimensi
165
165
  ```ruby
166
166
  sales[-:price, -:quantity]
167
167
  # => #<Namo [
168
- # {product: 'Widget', quarter: 'Q1'},
169
- # {product: 'Widget', quarter: 'Q2'},
170
- # {product: 'Gadget', quarter: 'Q1'},
171
- # {product: 'Gadget', quarter: 'Q2'}
168
+ # {product: "Widget", quarter: "Q1"},
169
+ # {product: "Widget", quarter: "Q2"},
170
+ # {product: "Gadget", quarter: "Q1"},
171
+ # {product: "Gadget", quarter: "Q2"}
172
172
  # ]>
173
173
  ```
174
174
 
@@ -183,8 +183,8 @@ Selection and contraction can be chained:
183
183
  ```ruby
184
184
  sales[product: 'Widget'][-:price, -:quantity]
185
185
  # => #<Namo [
186
- # {product: 'Widget', quarter: 'Q1'},
187
- # {product: 'Widget', quarter: 'Q2'}
186
+ # {product: "Widget", quarter: "Q1"},
187
+ # {product: "Widget", quarter: "Q2"}
188
188
  # ]>
189
189
  ```
190
190
 
@@ -193,8 +193,8 @@ Or combined in a single call (names before selectors):
193
193
  ```ruby
194
194
  sales[-:price, -:quantity, product: 'Widget']
195
195
  # => #<Namo [
196
- # {product: 'Widget', quarter: 'Q1'},
197
- # {product: 'Widget', quarter: 'Q2'}
196
+ # {product: "Widget", quarter: "Q1"},
197
+ # {product: "Widget", quarter: "Q2"}
198
198
  # ]>
199
199
  ```
200
200
 
@@ -219,10 +219,10 @@ q2_sales = Namo.new([
219
219
 
220
220
  all_sales = q1_sales + q2_sales
221
221
  # => #<Namo [
222
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
223
- # {product: 'Gadget', quarter: 'Q1', price: 25.0, quantity: 40},
224
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150},
225
- # {product: 'Gadget', quarter: 'Q2', price: 25.0, quantity: 60}
222
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
223
+ # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40},
224
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150},
225
+ # {product: "Gadget", quarter: "Q2", price: 25.0, quantity: 60}
226
226
  # ]>
227
227
  ```
228
228
 
@@ -247,8 +247,8 @@ discontinued = Namo.new([
247
247
 
248
248
  sales - discontinued
249
249
  # => #<Namo [
250
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
251
- # {product: 'Widget', quarter: 'Q2', price: 10.0, quantity: 150}
250
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
251
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150}
252
252
  # ]>
253
253
  ```
254
254
 
@@ -273,8 +273,8 @@ confirmed = Namo.new([
273
273
 
274
274
  sales & confirmed
275
275
  # => #<Namo [
276
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
277
- # {product: 'Gadget', quarter: 'Q2', price: 25.0, quantity: 60}
276
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
277
+ # {product: "Gadget", quarter: "Q2", price: 25.0, quantity: 60}
278
278
  # ]>
279
279
  ```
280
280
 
@@ -297,9 +297,9 @@ all_sales = Namo.new([
297
297
 
298
298
  q1_sales | all_sales
299
299
  # => #<Namo [
300
- # {product: 'Widget', quarter: 'Q1', price: 10.0, quantity: 100},
301
- # {product: 'Gadget', quarter: 'Q1', price: 25.0, quantity: 40},
302
- # {product: 'Thingo', quarter: 'Q3', price: 5.0, quantity: 10}
300
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
301
+ # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40},
302
+ # {product: "Thingo", quarter: "Q3", price: 5.0, quantity: 10}
303
303
  # ]>
304
304
  ```
305
305
 
@@ -322,8 +322,8 @@ set_b = Namo.new([
322
322
 
323
323
  set_a ^ set_b
324
324
  # => #<Namo [
325
- # {product: 'Gadget', quarter: 'Q1', price: 25.0, quantity: 40},
326
- # {product: 'Thingo', quarter: 'Q3', price: 5.0, quantity: 10}
325
+ # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40},
326
+ # {product: "Thingo", quarter: "Q3", price: 5.0, quantity: 10}
327
327
  # ]>
328
328
  ```
329
329
 
@@ -346,8 +346,8 @@ fundamentals = Namo.new([
346
346
 
347
347
  ohlcv * fundamentals
348
348
  # => #<Namo [
349
- # {symbol: 'BHP', date: '2025-01-01', close: 42.5, pe: 14.5},
350
- # {symbol: 'RIO', date: '2025-01-01', close: 118.3, pe: 9.2}
349
+ # {symbol: "BHP", date: "2025-01-01", close: 42.5, pe: 14.5},
350
+ # {symbol: "RIO", date: "2025-01-01", close: 118.3, pe: 9.2}
351
351
  # ]>
352
352
  ```
353
353
 
@@ -376,8 +376,8 @@ prices.*(quarterly) do |row, candidates|
376
376
  candidates[quarter_end: ->(qe){qe <= row[:date]}].sort_by{|f| f[:quarter_end]}.last(1)
377
377
  end
378
378
  # => #<Namo [
379
- # {symbol: 'BHP', date: '2025-02-15', close: 42.5, quarter_end: '2024-12-31', eps: 1.0},
380
- # {symbol: 'BHP', date: '2025-05-20', close: 44.0, quarter_end: '2025-03-31', eps: 1.2}
379
+ # {symbol: "BHP", date: "2025-02-15", close: 42.5, quarter_end: "2024-12-31", eps: 1.0},
380
+ # {symbol: "BHP", date: "2025-05-20", close: 44.0, quarter_end: "2025-03-31", eps: 1.2}
381
381
  # ]>
382
382
  ```
383
383
 
@@ -395,10 +395,10 @@ quarters = Namo.new([{quarter: 'Q1'}, {quarter: 'Q2'}])
395
395
 
396
396
  products ** quarters
397
397
  # => #<Namo [
398
- # {product: 'Widget', quarter: 'Q1'},
399
- # {product: 'Widget', quarter: 'Q2'},
400
- # {product: 'Gadget', quarter: 'Q1'},
401
- # {product: 'Gadget', quarter: 'Q2'}
398
+ # {product: "Widget", quarter: "Q1"},
399
+ # {product: "Widget", quarter: "Q2"},
400
+ # {product: "Gadget", quarter: "Q1"},
401
+ # {product: "Gadget", quarter: "Q2"}
402
402
  # ]>
403
403
  ```
404
404
 
@@ -429,9 +429,9 @@ orders.**(tiers) do |row, candidates|
429
429
  candidates[max_weight: ->(w){w >= row[:weight]}]
430
430
  end
431
431
  # => #<Namo [
432
- # {order: 'A', weight: 5, tier: 'light', max_weight: 10},
433
- # {order: 'A', weight: 5, tier: 'heavy', max_weight: 20},
434
- # {order: 'B', weight: 15, tier: 'heavy', max_weight: 20}
432
+ # {order: "A", weight: 5, tier: "light", max_weight: 10},
433
+ # {order: "A", weight: 5, tier: "heavy", max_weight: 20},
434
+ # {order: "B", weight: 15, tier: "heavy", max_weight: 20}
435
435
  # ]>
436
436
  ```
437
437
 
@@ -454,8 +454,8 @@ fundamentals = Namo.new([
454
454
 
455
455
  combined / fundamentals
456
456
  # => #<Namo [
457
- # {date: '2025-01-01', close: 42.5},
458
- # {date: '2025-01-01', close: 118.3}
457
+ # {date: "2025-01-01", close: 42.5},
458
+ # {date: "2025-01-01", close: 118.3}
459
459
  # ]>
460
460
  ```
461
461
 
@@ -616,10 +616,10 @@ sales[:revenue] = proc{|row| row[:price] * row[:quantity]}
616
616
 
617
617
  sales[:product, :quarter, :revenue]
618
618
  # => #<Namo [
619
- # {product: 'Widget', quarter: 'Q1', revenue: 1000.0},
620
- # {product: 'Widget', quarter: 'Q2', revenue: 1500.0},
621
- # {product: 'Gadget', quarter: 'Q1', revenue: 1000.0},
622
- # {product: 'Gadget', quarter: 'Q2', revenue: 1500.0}
619
+ # {product: "Widget", quarter: "Q1", revenue: 1000.0},
620
+ # {product: "Widget", quarter: "Q2", revenue: 1500.0},
621
+ # {product: "Gadget", quarter: "Q1", revenue: 1000.0},
622
+ # {product: "Gadget", quarter: "Q2", revenue: 1500.0}
623
623
  # ]>
624
624
  ```
625
625
 
@@ -633,11 +633,11 @@ sales[:profit] = proc{|row| row[:revenue] - row[:cost]}
633
633
 
634
634
  sales[:product, :quarter, :profit]
635
635
  # => #<Namo [
636
- # {product: 'Widget', quarter: 'Q1', profit: 600.0},
637
- # {product: 'Widget', quarter: 'Q2', profit: 900.0},
638
- # {product: 'Gadget', quarter: 'Q1', profit: 840.0},
639
- # {product: 'Gadget', quarter: 'Q2', profit: 1260.0}
640
- # ]>
636
+ # {product: "Widget", quarter: "Q1", profit: 600.0},
637
+ # {product: "Widget", quarter: "Q2", profit: 900.0},
638
+ # {product: "Gadget", quarter: "Q1", profit: 840.0},
639
+ # {product: "Gadget", quarter: "Q2", profit: 1260.0}
640
+ # ] derived: [:revenue, :cost]>
641
641
  ```
642
642
 
643
643
  Formulae work with selection and projection:
@@ -645,9 +645,9 @@ Formulae work with selection and projection:
645
645
  ```ruby
646
646
  sales[product: 'Widget'][:revenue, :quarter]
647
647
  # => #<Namo [
648
- # {revenue: 1000.0, quarter: 'Q1'},
649
- # {revenue: 1500.0, quarter: 'Q2'}
650
- # ]>
648
+ # {revenue: 1000.0, quarter: "Q1"},
649
+ # {revenue: 1500.0, quarter: "Q2"}
650
+ # ] derived: [:cost, :profit]>
651
651
  ```
652
652
 
653
653
  Formulae carry through selection — a filtered Namo instance remembers its formulae.
@@ -970,6 +970,36 @@ sales[:product, :quarter, :revenue].to_h
970
970
  # }
971
971
  ```
972
972
 
973
+ ### Inspection output
974
+
975
+ `inspect` renders the class, the stored rows, and the names of any derived dimensions:
976
+
977
+ ```ruby
978
+ sales.inspect
979
+ # => #<Namo [
980
+ # {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100},
981
+ # {product: "Widget", quarter: "Q2", price: 10.0, quantity: 150},
982
+ # {product: "Gadget", quarter: "Q1", price: 25.0, quantity: 40},
983
+ # {product: "Gadget", quarter: "Q2", price: 25.0, quantity: 60}
984
+ # ] derived: [:revenue]>
985
+ ```
986
+
987
+ A name, where the Namo carries one, follows the class: `#<Namo :sales [`. A subclass reports its own name in place of `Namo`.
988
+
989
+ Derived dimensions are *named*, not evaluated. A console calls `inspect` on every result, so evaluating there would cost a pass over the data on each one, would raise whatever a formula raises, and could not render a parameterised formula at all. Ask through `values`, `coordinates`, or a projection when you want the values.
990
+
991
+ 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`.
992
+
993
+ A `Row` renders itself 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.
994
+
995
+ ```ruby
996
+ sales.first
997
+ # => #<Namo::Row {product: "Widget", quarter: "Q1", price: 10.0, quantity: 100} derived: [:revenue]>
998
+
999
+ sales.group_by(:quarter)
1000
+ # => #<Namo::Collection members: ["Q1", "Q2"], 4 rows>
1001
+ ```
1002
+
973
1003
  ### Named Namos
974
1004
 
975
1005
  A Namo can carry a name, passed by the `name:` keyword and read or set through the `name` accessor:
@@ -53,6 +53,10 @@ class Namo
53
53
  self
54
54
  end
55
55
 
56
+ def inspect
57
+ "#<#{self.class}#{inspected_name} members: #{@members.map(&:name).inspect}, #{@data.length} rows#{inspected_derived}>"
58
+ end
59
+
56
60
  private
57
61
 
58
62
  def initialize(positional_data = nil, data: [], formulae: {}, name: nil)
data/lib/Namo/Formulae.rb CHANGED
@@ -97,6 +97,10 @@ class Namo
97
97
  keys.sort.hash
98
98
  end
99
99
 
100
+ def inspect
101
+ "#<#{self.class} #{@store.keys.inspect}>"
102
+ end
103
+
100
104
  private
101
105
 
102
106
  def initialize(store = {})
data/lib/Namo/Row.rb CHANGED
@@ -43,8 +43,16 @@ class Namo
43
43
  @row
44
44
  end
45
45
 
46
+ def inspect
47
+ "#<#{self.class} #{@row.inspect}#{inspected_derived}>"
48
+ end
49
+
46
50
  private
47
51
 
52
+ def inspected_derived
53
+ @formulae.keys.empty? ? '' : " derived: #{@formulae.keys.inspect}"
54
+ end
55
+
48
56
  def initialize(row, formulae, namo = nil)
49
57
  @row = row
50
58
  @formulae = formulae
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.30.0'
5
+ VERSION = '0.31.0'
6
6
  end
data/lib/namo.rb CHANGED
@@ -17,6 +17,8 @@ class Namo
17
17
  attr_accessor :formulae
18
18
  attr_accessor :name
19
19
 
20
+ INSPECTED_ROWS = 10
21
+
20
22
  def dimensions
21
23
  data_dimensions + derived_dimensions
22
24
  end
@@ -247,6 +249,10 @@ class Namo
247
249
  end
248
250
  end
249
251
 
252
+ def inspect
253
+ "#<#{self.class}#{inspected_name}#{inspected_rows}#{inspected_derived}>"
254
+ end
255
+
250
256
  protected
251
257
 
252
258
  def row_multiset
@@ -265,6 +271,24 @@ class Namo
265
271
 
266
272
  private
267
273
 
274
+ def inspected_name
275
+ @name.nil? ? '' : " #{@name.inspect}"
276
+ end
277
+
278
+ # The rows as they are stored, never the derived values: inspect is called
279
+ # for every result in a console, and evaluating a formula there would cost a
280
+ # pass over the data per access and raise whatever the formula raises.
281
+ def inspected_rows
282
+ return ' []' if @data.empty?
283
+ shown = @data.first(INSPECTED_ROWS).map{|row| " #{row.inspect}"}.join(",\n")
284
+ shown += "\n ... #{@data.length - INSPECTED_ROWS} more rows" if @data.length > INSPECTED_ROWS
285
+ " [\n#{shown}\n]"
286
+ end
287
+
288
+ def inspected_derived
289
+ derived_dimensions.empty? ? '' : " derived: #{derived_dimensions.inspect}"
290
+ end
291
+
268
292
  def initialize(positional_data = nil, data: [], formulae: {}, name: nil)
269
293
  @data = positional_data || data
270
294
  @formulae = formulae.is_a?(Formulae) ? formulae : Formulae.new(formulae)
data/namo.gemspec CHANGED
@@ -22,14 +22,14 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.files = [
25
- 'namo.gemspec',
25
+ Dir['lib/**/*.rb'],
26
+ Dir['test/**/*.rb'],
26
27
  'CHANGELOG',
27
28
  'Gemfile',
28
29
  'LICENSE',
30
+ 'namo.gemspec',
29
31
  'Rakefile',
30
32
  'README.md',
31
- Dir['lib/**/*.rb'],
32
- Dir['test/**/*.rb'],
33
33
  ].flatten
34
34
 
35
35
  spec.development_dependencies = %w{
@@ -346,4 +346,17 @@ describe Namo::Collection do
346
346
  _(car.detail.values(:assembly)).must_equal [:powertrain, :powertrain, :chassis, :body]
347
347
  end
348
348
  end
349
+
350
+ describe "#inspect" do
351
+ it "renders the member names and the row count" do
352
+ collection = Namo::Collection.new
353
+ collection << Namo.new([{a: 1}], name: :first) << Namo.new([{a: 2}], name: :second)
354
+ _(collection.inspect).must_equal "#<Namo::Collection members: [:first, :second], 2 rows>"
355
+ end
356
+
357
+ it "renders an empty Collection" do
358
+ _(Namo::Collection.new.inspect).must_equal "#<Namo::Collection members: [], 0 rows>"
359
+ end
360
+ end
361
+
349
362
  end
@@ -440,4 +440,19 @@ describe Namo::Formulae do
440
440
  end
441
441
  end
442
442
  end
443
+
444
+ describe "#inspect" do
445
+ it "renders the formula names" do
446
+ formulae = Namo::Formulae.new
447
+ formulae[:revenue] = proc{|row| row[:price]}
448
+ _(formulae.inspect).must_equal "#<Namo::Formulae [:revenue]>"
449
+ end
450
+
451
+ it "does not render the callables" do
452
+ formulae = Namo::Formulae.new
453
+ formulae[:revenue] = proc{|row| row[:price]}
454
+ _(formulae.inspect).wont_match(/Proc/)
455
+ end
456
+ end
457
+
443
458
  end
@@ -459,4 +459,23 @@ describe Namo::Row do
459
459
  _([a, b, duplicate_of_a].uniq.length).must_equal 2
460
460
  end
461
461
  end
462
+
463
+ describe "#inspect" do
464
+ it "renders the row data" do
465
+ _(Namo::Row.new({a: 1}, Namo::Formulae.new).inspect).must_equal "#<Namo::Row {a: 1}>"
466
+ end
467
+
468
+ it "names derived dimensions without evaluating them" do
469
+ formulae = Namo::Formulae.new
470
+ formulae[:b] = proc{|row| raise 'never called'}
471
+ _(Namo::Row.new({a: 1}, formulae).inspect).must_equal "#<Namo::Row {a: 1} derived: [:b]>"
472
+ end
473
+
474
+ it "does not render the Namo the row came from" do
475
+ namo = Namo.new((1..1000).map{|i| {a: i}})
476
+ _(namo.first.inspect).wont_match(/\{a: 2\}/)
477
+ _(namo.first.inspect.length).must_be :<, 100
478
+ end
479
+ end
480
+
462
481
  end
data/test/namo_test.rb CHANGED
@@ -3221,4 +3221,49 @@ describe Namo do
3221
3221
  end
3222
3222
  end
3223
3223
  end
3224
+
3225
+ describe "#inspect" do
3226
+ it "renders the class and the rows" do
3227
+ _(Namo.new([{a: 1}]).inspect).must_equal "#<Namo [\n {a: 1}\n]>"
3228
+ end
3229
+
3230
+ it "renders an empty Namo without a row block" do
3231
+ _(Namo.new([]).inspect).must_equal "#<Namo []>"
3232
+ end
3233
+
3234
+ it "names derived dimensions without evaluating them" do
3235
+ namo = Namo.new([{a: 1}])
3236
+ namo[:b] = proc{|row| raise 'never called'}
3237
+ _(namo.inspect).must_equal "#<Namo [\n {a: 1}\n] derived: [:b]>"
3238
+ end
3239
+
3240
+ it "includes the name when there is one" do
3241
+ _(Namo.new([{a: 1}], name: :sales).inspect).must_match(/\A#<Namo :sales \[/)
3242
+ end
3243
+
3244
+ it "omits the name when there is none" do
3245
+ _(Namo.new([{a: 1}]).inspect).must_match(/\A#<Namo \[/)
3246
+ end
3247
+
3248
+ it "truncates beyond INSPECTED_ROWS and says how many are left" do
3249
+ namo = Namo.new((1..25).map{|i| {a: i}})
3250
+ _(namo.inspect.scan(/\{a: \d+\}/).length).must_equal Namo::INSPECTED_ROWS
3251
+ _(namo.inspect).must_match(/\.\.\. 15 more rows/)
3252
+ end
3253
+
3254
+ it "does not truncate at exactly INSPECTED_ROWS" do
3255
+ namo = Namo.new((1..Namo::INSPECTED_ROWS).map{|i| {a: i}})
3256
+ _(namo.inspect).wont_match(/more rows/)
3257
+ end
3258
+
3259
+ it "reports the subclass rather than Namo" do
3260
+ Object.const_set(:InspectedSubAssembly, Class.new(Namo)) unless defined?(InspectedSubAssembly)
3261
+ _(InspectedSubAssembly.new([{a: 1}]).inspect).must_match(/\A#<InspectedSubAssembly \[/)
3262
+ end
3263
+
3264
+ it "does not grow with the data beyond the truncation point" do
3265
+ _(Namo.new((1..10_000).map{|i| {a: i}}).inspect.length).must_be :<, 500
3266
+ end
3267
+ end
3268
+
3224
3269
  end
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.30.0
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 4.0.16
101
+ rubygems_version: 4.0.18
102
102
  specification_version: 4
103
103
  summary: Named dimensional data for Ruby.
104
104
  test_files: []