ouroboros 0.1.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: 040b53849fd78ac0d7ba8d56d540a90d5ae3ebc99890bf5283d228a6db6a3b45
4
+ data.tar.gz: 831116ffaff26ce393ba9348661f1eb4d839e3e53b8588d0ca23141223bf3e15
5
+ SHA512:
6
+ metadata.gz: 6cbaff34ebe40a0e072c9fd4a6a6250d9a9e5ea87d6ed0091d2a022922de76764e473ea33ce8a5a4d2cd46a8e1ff615047254bed5e4c9321a0c554f51e83115d
7
+ data.tar.gz: 21ed67fa4579b7e5e36cacb04851a38f029e4e29067a897c8fa0e396bf2a675f1f0b1f117e3e5ebdd1c3a785ad579dbb44775d202db3c02d16af40b26a62fe40
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-25
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 TODO: Write your name
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # Ouroboros
2
+
3
+ Ouroboros is an experimental implementation of an infinite circular Array. An Array eating it's own tail.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add ouroboros
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install ouroboros
14
+
15
+ ## Motivation
16
+
17
+ Supporting an application which had rota patterns with a format like D (Day), N (Night), O (Day off), L (Long day). This pattern needed to be allocated to each Junior Doctor in turn `rota[0]` on week 1 through to `rota[19]` on week 20. What became apparant is that this pattern needed to be exploded
18
+
19
+ ```
20
+ rota = [
21
+ # Mon Tue Wed Thu Fri Sat Sun
22
+ [ 'L', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 1
23
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 2
24
+ [ 'D', 'D', 'D', 'D', 'L', 'O', 'O' ], # week 3
25
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'L' ], # week 4
26
+ [ 'D', 'D', 'D', 'L', 'D', 'O', 'O' ], # week 5
27
+ [ 'D', 'L', 'D', 'D', 'D', 'O', 'O' ], # week 6
28
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 7
29
+ [ 'N', 'N', 'N', 'N', 'O', 'O', 'O' ], # week 8
30
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 9
31
+ [ 'D', 'D', 'D', 'D', 'D', 'L', 'O' ], # week 10
32
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 11
33
+ [ 'D', 'D', 'L', 'D', 'D', 'O', 'O' ], # week 12
34
+ [ 'D', 'D', 'D', 'D', 'N', 'N', 'N' ], # week 13
35
+ [ 'O', 'O', 'D', 'D', 'D', 'O', 'O' ], # week 14
36
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 15
37
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 16
38
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 17
39
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 18
40
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ], # week 19
41
+ [ 'D', 'D', 'D', 'D', 'D', 'O', 'O' ] # week 20
42
+ ]
43
+ ```
44
+
45
+ Into one series of shifts and this pattern could then run in a cycle for 20 weeks, or 52 weeks or even 60 weeks. The pattern just repeats. And then it might even start on the Wednesday so this pattern would have to be rotated.
46
+
47
+ ```
48
+ [ 'L', 'D', 'D', 'D', 'D', 'O', 'O', 'D', 'D', 'D', 'D', 'D', 'O', 'O'] # etc.
49
+ ```
50
+
51
+ In order to manage these potentially infinite cyclic patterns an `Ouroboros::Array` can be used to simplify accessing shifts for a particular Doctor on day 999 of a recurring pattern.
52
+
53
+ ## Usage
54
+
55
+ Instantiate an `Ouroboros::Array`
56
+
57
+ ```ruby
58
+ [1, 2, 3, 4, 5].to_ouroboros
59
+ # or
60
+ Ouroboros::Array.new([1, 2, 3, 4, 5])
61
+ ```
62
+
63
+ Using the usual suspects `at`
64
+
65
+ ```
66
+ o = [1, 2, 3, 4, 5].to_ouroboros
67
+ o.at(0) #=> 1
68
+ o.at(5) #=> 1
69
+ o.at(298) #=> 4
70
+ o.at(-218) #=> 3
71
+ ```
72
+
73
+ or `[]`
74
+
75
+ ```
76
+ o = [1, 2, 3, 4, 5].to_ouroboros
77
+
78
+ # with index
79
+ o[0] #=> 1
80
+ o[5] #=> 1
81
+ o[298] #=> 4
82
+ o[-418] #=> 3
83
+
84
+ # with index, size
85
+ o[1, 12] #=> Ouroboros::Array[2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3]
86
+ o[4, 9] #=> Ouroboros::Array[5, 1, 2, 3, 4, 5, 1, 2, 3]
87
+
88
+ # with range
89
+ o[1..12] #=> Ouroboros::Array[2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3]
90
+ o[4..9] #=> Ouroboros::Array[5, 1, 2, 3, 4, 5]
91
+ ```
92
+
93
+ Other `Array` methods are available
94
+
95
+ ```
96
+ o = [1, 2, 3, 4, 5].to_ouroboros
97
+ o.rotate(2) #=> Ouroboros::Array[3, 4, 5, 1, 2]
98
+
99
+ ```
100
+
101
+ ## Development
102
+
103
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
+
105
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/braindeaf/ouroboros.
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,50 @@
1
+ module Ouroboros
2
+ class Array
3
+
4
+ attr_reader :store
5
+
6
+ def initialize(args = [])
7
+ @store = ::Array.new(args)
8
+ end
9
+
10
+ def inspect
11
+ "#{self.class.name}#{store}"
12
+ end
13
+
14
+ def [](*args)
15
+ case args
16
+ in ::Array[Range => range]
17
+ send(:[], range.begin, range.size)
18
+
19
+ in ::Array[Integer => start, Integer => length]
20
+ base = store.rotate(start % store.size)
21
+ times, remainder = length.divmod(store.size)
22
+ Array.new([*(base * times), *base[0, remainder]])
23
+
24
+ in ::Array[Integer => index]
25
+ at(index)
26
+
27
+ else
28
+ store.send(:[], *args).then { |o| o.is_a?(::Array) ? Array.new(o) : o }
29
+ end
30
+ end
31
+
32
+ def ==(other)
33
+ other == store
34
+ end
35
+
36
+ def at(index)
37
+ store.at(index % store.size)
38
+ end
39
+
40
+ private
41
+
42
+ def method_missing(m, *args, &block)
43
+ store.send(m, *args, &block).then { |o| o.is_a?(::Array) ? Array.new(o) : o }
44
+ end
45
+
46
+ def respond_to_missing?(m, include_private=false)
47
+ data.respond_to?(m, include_private)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module Ouroboros
2
+ module CoreExt
3
+ module Array
4
+ def to_ouroboros
5
+ Ouroboros::Array.new(self)
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ ::Array.include(Ouroboros::CoreExt::Array)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ouroboros
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ouroboros.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ouroboros/core_ext/array"
4
+ require_relative "ouroboros/array"
5
+ require_relative "ouroboros/version"
data/ouroboros.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ouroboros/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ouroboros"
7
+ spec.version = Ouroboros::VERSION
8
+ spec.authors = ["RobL"]
9
+ spec.email = ["contact@robl.me"]
10
+
11
+ spec.summary = "Circular, Infinite Arrays in Ruby"
12
+ spec.description = "Ouroboros is an experimental implementation of an infinite circular Array. An Array eating it's own tail. "
13
+ spec.homepage = "https://github.com/braindeaf/ouroboros"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/braindeaf/ouroboros"
19
+ spec.metadata["changelog_uri"] = "https://github.com/braindeaf/ouroboros/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
27
+ end
28
+ end
29
+
30
+ spec.require_paths = ["lib"]
31
+ end
data/sig/ouroboros.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Ouroboros
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ouroboros
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RobL
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: 'Ouroboros is an experimental implementation of an infinite circular
13
+ Array. An Array eating it''s own tail. '
14
+ email:
15
+ - contact@robl.me
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".standard.yml"
22
+ - CHANGELOG.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/ouroboros.rb
27
+ - lib/ouroboros/array.rb
28
+ - lib/ouroboros/core_ext/array.rb
29
+ - lib/ouroboros/version.rb
30
+ - ouroboros.gemspec
31
+ - sig/ouroboros.rbs
32
+ homepage: https://github.com/braindeaf/ouroboros
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/braindeaf/ouroboros
37
+ source_code_uri: https://github.com/braindeaf/ouroboros
38
+ changelog_uri: https://github.com/braindeaf/ouroboros/CHANGELOG.md
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.6.9
54
+ specification_version: 4
55
+ summary: Circular, Infinite Arrays in Ruby
56
+ test_files: []