bcd 0.3 → 1.0.1
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 +5 -5
- data/.github/workflows/ruby.yaml +25 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +11 -0
- data/Rakefile +4 -2
- data/bcd.gemspec +12 -9
- data/lib/bcd.rb +12 -12
- data/test/test_bcd.rb +5 -2
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8345a229c3a07b8fb0c35d66d48739fd08a4f6a4482fc861e5857027266c85fd
|
4
|
+
data.tar.gz: f507b3d23278d6c9211e9fc7839b42b0f88053aaa9ff28c67d98f33685ba3f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d81ccf95c501f76de100b0b613186a82af7656b7fe88aadb2de3d3010cc80cda10454227078e4459871a094918485432f63f4b5cb44b4a833ea9acd3aa91743
|
7
|
+
data.tar.gz: 67ad12ce9f96fa2a3c9cbd330e9ed2e9503c5278f0c383596b1e14393535fc7644db9f90227f567698cd0e457ecb97955456b429ae8ec0103e688e3563dbd153
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Ruby
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ main ]
|
5
|
+
pull_request:
|
6
|
+
branches: [ main ]
|
7
|
+
permissions:
|
8
|
+
contents: read
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
env:
|
13
|
+
BUNDLE_WITH: development
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- name: Set up Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
data/bcd.gemspec
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
1
4
|
Gem::Specification.new do |gem|
|
2
5
|
gem.name = 'bcd'
|
3
|
-
gem.version = '0.
|
4
|
-
gem.summary =
|
5
|
-
gem.description =
|
6
|
-
gem.author = '
|
6
|
+
gem.version = '1.0.1'
|
7
|
+
gem.summary = 'Binary Coded Decimal library'
|
8
|
+
gem.description = 'A library for decoding and encoding binary coded decimal'
|
9
|
+
gem.author = 'David Crosby'
|
7
10
|
gem.email = 'dafydd@dafyddcrosby.com'
|
8
11
|
gem.homepage = 'https://github.com/dafyddcrosby/ruby_bcd'
|
9
|
-
gem.required_ruby_version = '>=
|
10
|
-
gem.files = `git ls-files`.split(
|
11
|
-
gem.
|
12
|
-
gem.
|
13
|
-
gem.
|
12
|
+
gem.required_ruby_version = '>= 2.5'
|
13
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.license = 'BSD-2-Clause'
|
16
|
+
gem.metadata['rubygems_mfa_required'] = 'true'
|
14
17
|
end
|
data/lib/bcd.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Methods to translate to and from binary coded decimal
|
2
4
|
#
|
3
|
-
# Author::
|
4
|
-
# Copyright:: Copyright 2013
|
5
|
+
# Author:: David Crosby <dafydd@dafyddcrosby.com>
|
6
|
+
# Copyright:: Copyright 2013-2022 David Crosby
|
5
7
|
# License:: BSD 2-clause
|
6
8
|
|
7
9
|
module BCD
|
8
10
|
# Translates binary coded decimal into an integer
|
9
11
|
def self.decode(bcd)
|
10
12
|
raise ArgumentError, 'Argument is not numeric' unless bcd.is_a? Numeric
|
11
|
-
raise ArgumentError, 'Cannot be a negative integer' if bcd
|
13
|
+
raise ArgumentError, 'Cannot be a negative integer' if bcd.negative?
|
12
14
|
|
13
|
-
binstring =
|
14
|
-
|
15
|
+
binstring = String.new
|
16
|
+
loop do
|
15
17
|
q, r = bcd.divmod(10)
|
16
18
|
nibble = r.to_s(2)
|
17
|
-
while nibble.length < 4
|
18
|
-
nibble.prepend('0')
|
19
|
-
end
|
19
|
+
nibble.prepend('0') while nibble.length < 4
|
20
20
|
binstring.prepend(nibble)
|
21
|
-
q
|
21
|
+
q.zero? ? break : bcd = q
|
22
22
|
end
|
23
23
|
|
24
24
|
binstring.to_i(2)
|
@@ -27,10 +27,10 @@ module BCD
|
|
27
27
|
# Translate an integer into binary coded decimal
|
28
28
|
def self.encode(int)
|
29
29
|
raise ArgumentError, 'Argument is not numeric' unless int.is_a? Numeric
|
30
|
-
raise ArgumentError, 'Cannot be a negative integer' if int
|
30
|
+
raise ArgumentError, 'Cannot be a negative integer' if int.negative?
|
31
31
|
|
32
|
-
bcdstring =
|
33
|
-
while int
|
32
|
+
bcdstring = String.new
|
33
|
+
while int.positive?
|
34
34
|
nibble = int % 16
|
35
35
|
bcdstring.prepend(nibble.to_s)
|
36
36
|
int >>= 4
|
data/test/test_bcd.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/pride'
|
2
5
|
require 'bcd'
|
3
6
|
|
4
|
-
class TestBCD < Test
|
7
|
+
class TestBCD < Minitest::Test
|
5
8
|
def test_encode
|
6
9
|
assert_equal 4, BCD.encode(4)
|
7
10
|
assert_equal 22, BCD.encode(34)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- David Crosby
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for decoding and encoding binary coded decimal
|
14
14
|
email: dafydd@dafyddcrosby.com
|
@@ -16,7 +16,10 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- .
|
19
|
+
- ".github/workflows/ruby.yaml"
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- Gemfile
|
20
23
|
- README.md
|
21
24
|
- Rakefile
|
22
25
|
- bcd.gemspec
|
@@ -24,27 +27,26 @@ files:
|
|
24
27
|
- test/test_bcd.rb
|
25
28
|
homepage: https://github.com/dafyddcrosby/ruby_bcd
|
26
29
|
licenses:
|
27
|
-
-
|
28
|
-
metadata:
|
29
|
-
|
30
|
+
- BSD-2-Clause
|
31
|
+
metadata:
|
32
|
+
rubygems_mfa_required: 'true'
|
33
|
+
post_install_message:
|
30
34
|
rdoc_options: []
|
31
35
|
require_paths:
|
32
36
|
- lib
|
33
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
34
38
|
requirements:
|
35
|
-
- -
|
39
|
+
- - ">="
|
36
40
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
41
|
+
version: '2.5'
|
38
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
|
-
- -
|
44
|
+
- - ">="
|
41
45
|
- !ruby/object:Gem::Version
|
42
46
|
version: '0'
|
43
47
|
requirements: []
|
44
|
-
|
45
|
-
|
46
|
-
signing_key:
|
48
|
+
rubygems_version: 3.3.7
|
49
|
+
signing_key:
|
47
50
|
specification_version: 4
|
48
51
|
summary: Binary Coded Decimal library
|
49
|
-
test_files:
|
50
|
-
- test/test_bcd.rb
|
52
|
+
test_files: []
|