namo 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90910055e2c50136c6b364a227484075c17a4d60f9aeb2eaff2f674d8b214271
4
+ data.tar.gz: 2210e6e62f753d9e337188f0a6d16095f85565d6f3dc0be5a918f5b1be22c378
5
+ SHA512:
6
+ metadata.gz: 89647d9897342b47358bc861a05a6b7861545b8257f57e6fd89b802f9deaaabc6b93b75af56f3ed7538e67be5e30fb7d522e20719ed2ce5135d19e7c22bdef37
7
+ data.tar.gz: '05669679f14b36cba17c1646ac0bfcd755d7c57a17d32ec5f5c2057ae67dde255c0c93b04b439eeb080067be143a317cece7891a9318006aa49159e819ec5558'
data/CHANGELOG ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG
2
+ _______
3
+
4
+ 2026-03-15
5
+ 0.0.0: Initial release.
6
+
7
+ 1. + Namo
8
+ 2. + Namo#initialize: Initialise from an array of hashes.
9
+ 3. + Namo#dimensions: Dimension names are inferred from hash keys.
10
+ 4. + Namo#coordinates: Extract the coordinates by finding unique values per dimension.
11
+ 5. + Namo#[]: Select by named dimension using keyword arguments, using any one of a single value, and array, or a range.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # Gemfile
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thoran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Namo
2
+
3
+ Named dimensional data for Ruby.
4
+
5
+ Namo is a Ruby library for working with multi-dimensional data using named dimensions. It infers dimensions and coordinates from plain arrays of hashes — the same shape you get from databases, CSV files, JSON, and YAML — so there's no reshaping step.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem install namo
11
+ ```
12
+
13
+ Or in your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'namo'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Create a Namo from an array of hashes:
22
+
23
+ ```ruby
24
+ require 'namo'
25
+
26
+ prices = Namo.new([
27
+ {date: '2025-01-01', symbol: 'BHP', close: 42.5},
28
+ {date: '2025-01-01', symbol: 'RIO', close: 118.3},
29
+ {date: '2025-01-02', symbol: 'BHP', close: 43.1},
30
+ {date: '2025-01-02', symbol: 'RIO', close: 117.8}
31
+ ])
32
+ ```
33
+
34
+ Dimensions and coordinates are inferred:
35
+
36
+ ```ruby
37
+ prices.dimensions
38
+ # => [:date, :symbol, :close]
39
+
40
+ prices.coordinates[:date]
41
+ # => ['2025-01-01', '2025-01-02']
42
+
43
+ prices.coordinates[:symbol]
44
+ # => ['BHP', 'RIO']
45
+ ```
46
+
47
+ Select by named dimension using keyword arguments:
48
+
49
+ ```ruby
50
+ # Single value
51
+ prices[symbol: 'BHP']
52
+
53
+ # Multiple dimensions
54
+ prices[date: '2025-01-01', symbol: 'BHP']
55
+
56
+ # Range
57
+ prices[close: 42.0..43.0]
58
+
59
+ # Array of values
60
+ prices[symbol: ['BHP', 'RIO']]
61
+
62
+ # All data
63
+ prices[]
64
+ ```
65
+
66
+ Selection always returns a new Namo. Omitting a dimension means "all values along that dimension."
67
+
68
+ ## Why?
69
+
70
+ Every other multi-dimensional array library requires you to pre-shape your data before you can work with it. Namo takes it in the form it already comes in.
71
+
72
+ ## Name
73
+
74
+ Namo: na(med) (di)m(ensi)o(ns). A companion to Numo (numeric arrays for Ruby).
75
+
76
+ ## Contributing
77
+
78
+ Fork it (https://github.com/thoran/namo/fork)
79
+ Create your feature branch (git checkout -b my-new-feature)
80
+ Commit your changes (git commit -am 'Add some feature')
81
+ Push to the branch (git push origin my-new-feature)
82
+ Create a new pull request
83
+ License
84
+ The gem is available as open source under the terms of the Ruby License.
85
+
86
+ ## License
87
+
88
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # Rakefile
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,6 @@
1
+ # Namo/VERSION.rb
2
+ # Namo::VERSION
3
+
4
+ module Namo
5
+ VERSION = '0.0.0'
6
+ end
data/lib/namo.rb ADDED
@@ -0,0 +1,38 @@
1
+ # namo.rb
2
+ # Namo
3
+
4
+ class Namo
5
+ def dimensions
6
+ @dimensions ||= @data.first.keys
7
+ end
8
+
9
+ def coordinates
10
+ @coordinates ||= (
11
+ dimensions.each_with_object({}) do |dimension, hash|
12
+ hash[dimension] = @data.map{|row| row[dimension]}.uniq
13
+ end
14
+ )
15
+ end
16
+
17
+ def [](**selections)
18
+ selected = (
19
+ @data.select do |row|
20
+ selections.all? do |dimension, coordinate|
21
+ case coordinate
22
+ when Array, Range
23
+ coordinate.include?(row[dimension])
24
+ else
25
+ coordinate == row[dimension]
26
+ end
27
+ end
28
+ end
29
+ )
30
+ self.class.new(selected)
31
+ end
32
+
33
+ private
34
+
35
+ def initialize(data)
36
+ @data = data
37
+ end
38
+ end
data/namo.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ require_relative './lib/Namo/VERSION'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'namo'
5
+ spec.date = '2026-03-15'
6
+ spec.version = Namo::VERSION
7
+
8
+ spec.summary = "Named dimensional data for Ruby."
9
+ spec.description = "A Ruby library for working with multi-dimensional data using named dimensions. Initialise from an array of hashes making it trivial to use with databases, CSV, JSON, and YAML. Dimensions and coordinates are inferred automatically."
10
+
11
+ spec.author = 'thoran'
12
+ spec.email = 'code@thoran.com'
13
+ spec.homepage = 'https://github.com/thoran/namo'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 2.7'
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.files = [
20
+ 'CHANGELOG',
21
+ 'Gemfile',
22
+ Dir['lib/**/*.rb'],
23
+ 'LICENSE',
24
+ 'namo.gemspec',
25
+ 'Rakefile',
26
+ 'README.md',
27
+ Dir['test/**/*.rb'],
28
+ ].flatten
29
+
30
+ spec.add_development_dependency 'minitest'
31
+ spec.add_development_dependency 'rake'
32
+ end
data/test/namo_test.rb ADDED
@@ -0,0 +1,70 @@
1
+ # namo_test.rb
2
+
3
+ # 20260314
4
+ # 0.0.0
5
+
6
+ require 'minitest/autorun'
7
+ require_relative '../lib/namo'
8
+
9
+ describe Namo do
10
+ let(:sample_data) do
11
+ [
12
+ {date: '2025-01-01', symbol: 'BHP', close: 42.5},
13
+ {date: '2025-01-01', symbol: 'RIO', close: 118.3},
14
+ {date: '2025-01-02', symbol: 'BHP', close: 43.1},
15
+ {date: '2025-01-02', symbol: 'RIO', close: 117.8}
16
+ ]
17
+ end
18
+
19
+ let(:namo){ Namo.new(sample_data) }
20
+
21
+ describe '#dimensions' do
22
+ it 'infers dimensions from hash keys' do
23
+ _(namo.dimensions).must_equal [:date, :symbol, :close]
24
+ end
25
+ end
26
+
27
+ describe '#coordinates' do
28
+ it 'extracts unique values per dimension' do
29
+ _(namo.coordinates[:date]).must_equal ['2025-01-01', '2025-01-02']
30
+ _(namo.coordinates[:symbol]).must_equal ['BHP', 'RIO']
31
+ _(namo.coordinates[:close]).must_equal [42.5, 118.3, 43.1, 117.8]
32
+ end
33
+ end
34
+
35
+ describe '#[]' do
36
+ it 'selects by single value' do
37
+ result = namo[symbol: 'BHP']
38
+ _(result.coordinates[:date]).must_equal ['2025-01-01', '2025-01-02']
39
+ _(result.coordinates[:symbol]).must_equal ['BHP']
40
+ _(result.coordinates[:close]).must_equal [42.5, 43.1]
41
+ end
42
+
43
+ it 'selects by multiple dimensions' do
44
+ result = namo[date: '2025-01-01', symbol: 'BHP']
45
+ _(result.coordinates[:date]).must_equal ['2025-01-01']
46
+ _(result.coordinates[:symbol]).must_equal ['BHP']
47
+ _(result.coordinates[:close]).must_equal [42.5]
48
+ end
49
+
50
+ it 'selects by range' do
51
+ result = namo[close: 42.0..43.0]
52
+ _(result.coordinates[:close]).must_equal [42.5]
53
+ end
54
+
55
+ it 'selects by array of values' do
56
+ result = namo[symbol: ['BHP', 'RIO']]
57
+ _(result.coordinates[:symbol]).must_equal ['BHP', 'RIO']
58
+ end
59
+
60
+ it 'returns a Namo' do
61
+ result = namo[symbol: 'BHP']
62
+ _(result).must_be_kind_of Namo
63
+ end
64
+
65
+ it 'returns all data when no selections given' do
66
+ result = namo[]
67
+ _(result.coordinates).must_equal namo.coordinates
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - thoran
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-03-15 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: A Ruby library for working with multi-dimensional data using named dimensions.
41
+ Initialise from an array of hashes making it trivial to use with databases, CSV,
42
+ JSON, and YAML. Dimensions and coordinates are inferred automatically.
43
+ email: code@thoran.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/Namo/VERSION.rb
54
+ - lib/namo.rb
55
+ - namo.gemspec
56
+ - test/namo_test.rb
57
+ homepage: https://github.com/thoran/namo
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 4.0.7
76
+ specification_version: 4
77
+ summary: Named dimensional data for Ruby.
78
+ test_files: []