dec_radix_50 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 +7 -0
- data/.rubocop.yml +13 -0
- data/.vscode/launch.json +21 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +16 -0
- data/dec_radix_50.gemspec +33 -0
- data/lib/dec_radix_50/encoder.rb +32 -0
- data/lib/dec_radix_50/version.rb +5 -0
- data/lib/dec_radix_50.rb +38 -0
- data/sig/dec_radix_50.rbs +4 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af13bb1390881961f4adcce1eef072dd44973202c75fba11bc05104be52761d1
|
4
|
+
data.tar.gz: abb419dfd9e600d6cc8f62e5a0bdc07bc424c7a5f2e079f50466bb92ca2abaf1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15cf0eb15e0dc49f14b2f4fde2ea77babfe76f32dfc9c340dd566f95edc244e85b9e7057955a4c379491e8750d567892832c84f16bf8ea79f2447d3cf580880a
|
7
|
+
data.tar.gz: 6b48b614e5c58b48e054e145991e43e6eb52dab8718fbb87ac832a239d41f5e701f1f0f3e8b56cb3bb0d80b28ad63b9ae6d03a4520cca45370aac47b920c1e59
|
data/.rubocop.yml
ADDED
data/.vscode/launch.json
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
3
|
+
// Hover to view descriptions of existing attributes.
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
+
"version": "0.2.0",
|
6
|
+
"configurations": [
|
7
|
+
{
|
8
|
+
"type": "rdbg",
|
9
|
+
"name": "Debug current file with rdbg",
|
10
|
+
"request": "launch",
|
11
|
+
"script": "${file}",
|
12
|
+
"args": [],
|
13
|
+
"askParameters": true
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"type": "rdbg",
|
17
|
+
"name": "Attach with rdbg",
|
18
|
+
"request": "attach"
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 8bit-m8
|
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,74 @@
|
|
1
|
+
# dec_radix_50.rb
|
2
|
+
|
3
|
+
Encodes strings to the DEC Radix-50 encoding.
|
4
|
+
|
5
|
+
**RADIX 50** is an uppercase-only character encoding created by Digital Equipment Corporation (DEC) for use on their PDP, and VAX computers. RADIX 50's 40-character repertoire (050 in octal) can encode three characters into one 16-bit word (PDP-11, VAX). It was also adapted for use on the Soviet PDP-11 clones, notably the Elektronika MK90 portable computer.
|
6
|
+
|
7
|
+
The actual encoding differs between the systems.
|
8
|
+
|
9
|
+
Learn more on the [Wikipedia](https://en.wikipedia.org/wiki/DEC_RADIX_50).
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application"s Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "dec_radix_50"
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install dec_radix_50
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
DECRadix50.encode(charset, string \[, replace_char = " "\]) => Array\<Integer\>
|
30
|
+
|
31
|
+
### Arguments
|
32
|
+
|
33
|
+
+ **charset**: character set, should be 40 characters long.
|
34
|
+
|
35
|
+
The gem comes with two predefined characters sets:
|
36
|
+
|
37
|
+
```Ruby
|
38
|
+
# Elektronika MK90 filenames charset:
|
39
|
+
MK90_CHARSET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$./0123456789"
|
40
|
+
|
41
|
+
# RT-11 filenames charset:
|
42
|
+
RT11_CHARSET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*0123456789"
|
43
|
+
```
|
44
|
+
|
45
|
+
+ **string**: string to encode.
|
46
|
+
|
47
|
+
+ **replace_char**: replaces unsupported characters. Default value is " " (a space).
|
48
|
+
|
49
|
+
### Returns
|
50
|
+
|
51
|
+
+ Array of integers.
|
52
|
+
|
53
|
+
### Example:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require "dec_radix_50"
|
57
|
+
|
58
|
+
DECRadix50.encode(DECRadix50::MK90_CHARSET, "ABCDEF")
|
59
|
+
# => [1683, 6606]
|
60
|
+
```
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
65
|
+
|
66
|
+
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).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/8bit-mate/dec_radix_50.rb.
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
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,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/dec_radix_50/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "dec_radix_50"
|
7
|
+
spec.version = DECRadix50::VERSION
|
8
|
+
spec.authors = ["8bit-m8"]
|
9
|
+
spec.email = ["you@example.com"]
|
10
|
+
|
11
|
+
spec.summary = "DEC RADIX 50 encoding."
|
12
|
+
spec.homepage = "https://github.com/8bit-mate/dec_radix_50.rb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 3.0.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DECRadix50
|
4
|
+
#
|
5
|
+
# Encodes strings to the DEC Radix-50 encoding.
|
6
|
+
#
|
7
|
+
class Encoder
|
8
|
+
def initialize(charset, string, replace_char)
|
9
|
+
_validate_input_parameters(charset, string, replace_char)
|
10
|
+
|
11
|
+
@charset = charset
|
12
|
+
@string = string.upcase.gsub(/[^#{charset}]/, replace_char)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Based on the @jgn/radix50.rb
|
16
|
+
# https://gist.github.com/jgn/707543
|
17
|
+
def encode
|
18
|
+
charset_values = @charset.split(//).each_with_index.to_h
|
19
|
+
@string.chars.each_slice(3).map do |x, y, z|
|
20
|
+
(((charset_values[x] || 0) * 40 + (charset_values[y] || 0)) * 40 + (charset_values[z] || 0))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def _validate_input_parameters(charset, string, replace_char)
|
27
|
+
raise DECRadix50::ArgumentError, "charset should be 40 characters long" unless charset.length == 40
|
28
|
+
raise DECRadix50::ArgumentError, "string shouldn't be empty" if string.empty?
|
29
|
+
raise DECRadix50::ArgumentError, "replace_char should be exactly 1 character long" unless replace_char.length == 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/dec_radix_50.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "dec_radix_50/encoder"
|
4
|
+
require_relative "dec_radix_50/version"
|
5
|
+
|
6
|
+
#
|
7
|
+
# Encodes strings to the DEC Radix-50 encoding.
|
8
|
+
#
|
9
|
+
module DECRadix50
|
10
|
+
class Error < StandardError; end
|
11
|
+
class ArgumentError < StandardError; end
|
12
|
+
|
13
|
+
# Elektronika MK90 filenames charset:
|
14
|
+
MK90_CHARSET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$./0123456789"
|
15
|
+
|
16
|
+
# RT-11 filenames charset:
|
17
|
+
RT11_CHARSET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*0123456789"
|
18
|
+
|
19
|
+
#
|
20
|
+
# Encode a string to the DEC Radix-50 encoding.
|
21
|
+
#
|
22
|
+
# @param [String] charset
|
23
|
+
# Should be 40 characters long.
|
24
|
+
#
|
25
|
+
# @param [String] string
|
26
|
+
# String to encode.
|
27
|
+
#
|
28
|
+
# @option [String] replace_char (" ")
|
29
|
+
# If a given string has characters that aren't included in the
|
30
|
+
# charset, they will be replaced with the replace_char.
|
31
|
+
#
|
32
|
+
# @return [Array<Integer>]
|
33
|
+
# Radix-50 (decimal numeral system).
|
34
|
+
#
|
35
|
+
def self.encode(charset, string, replace_char = " ")
|
36
|
+
Encoder.new(charset, string, replace_char).encode
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dec_radix_50
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 8bit-m8
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- you@example.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rubocop.yml"
|
21
|
+
- ".vscode/launch.json"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- dec_radix_50.gemspec
|
27
|
+
- lib/dec_radix_50.rb
|
28
|
+
- lib/dec_radix_50/encoder.rb
|
29
|
+
- lib/dec_radix_50/version.rb
|
30
|
+
- sig/dec_radix_50.rbs
|
31
|
+
homepage: https://github.com/8bit-mate/dec_radix_50.rb
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
allowed_push_host: https://rubygems.org
|
36
|
+
homepage_uri: https://github.com/8bit-mate/dec_radix_50.rb
|
37
|
+
source_code_uri: https://github.com/8bit-mate/dec_radix_50.rb
|
38
|
+
changelog_uri: https://github.com/8bit-mate/dec_radix_50.rb
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.4.10
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: DEC RADIX 50 encoding.
|
58
|
+
test_files: []
|