bcd 0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 32f1c0f41a42224ef25c90cd97ae4ec55668b6e4
4
- data.tar.gz: a5eb982d4f553eaca3ff51fcc24e03d1754a7961
2
+ SHA256:
3
+ metadata.gz: 8345a229c3a07b8fb0c35d66d48739fd08a4f6a4482fc861e5857027266c85fd
4
+ data.tar.gz: f507b3d23278d6c9211e9fc7839b42b0f88053aaa9ff28c67d98f33685ba3f95
5
5
  SHA512:
6
- metadata.gz: c9c0558a5cee280d7bebee0913dfce0d064de23fd43f29db0644b7f464b5eaec2d75190804c85e07e681668b4243fbf144a25068952e16e00cd20a2b210782d6
7
- data.tar.gz: 215ba5c0037d806b0461a1380cb89edac80312b2a926d7d1f9293608786c76b5c0b443f8db91c048c8ba09eeea62ac46c39cb53a651cb516f923a906596f2011
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
@@ -1 +1,4 @@
1
1
  *gem
2
+ vendor
3
+ .bundle
4
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.5
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :development, optional: true do
6
+ gem 'minitest'
7
+ gem 'rake'
8
+ gem 'rubocop'
9
+ gem 'rubocop-minitest'
10
+ gem 'rubocop-rake'
11
+ end
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/testtask'
2
4
 
3
5
  Rake::TestTask.new do |t|
4
6
  t.libs << 'test'
5
7
  end
6
8
 
7
- desc "Run tests"
8
- task :default => :test
9
+ desc 'Run tests'
10
+ task default: :test
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.3'
4
- gem.summary = %q{Binary Coded Decimal library}
5
- gem.description = %q{A library for decoding and encoding binary coded decimal}
6
- gem.author = 'Dafydd Crosby'
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 = '>= 1.9'
10
- gem.files = `git ls-files`.split($\)
11
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
- gem.require_paths = ["lib"]
13
- gem.license = 'bsd' # (two-clause) BSD license
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:: Dafydd Crosby <dafydd@dafyddcrosby.com>
4
- # Copyright:: Copyright 2013, Dafydd Crosby
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 < 0
13
+ raise ArgumentError, 'Cannot be a negative integer' if bcd.negative?
12
14
 
13
- binstring = ''
14
- while true do
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 do
18
- nibble.prepend('0')
19
- end
19
+ nibble.prepend('0') while nibble.length < 4
20
20
  binstring.prepend(nibble)
21
- q == 0 ? break : bcd = 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 < 0
30
+ raise ArgumentError, 'Cannot be a negative integer' if int.negative?
31
31
 
32
- bcdstring = ''
33
- while int > 0 do
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
- require 'test/unit'
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
2
5
  require 'bcd'
3
6
 
4
- class TestBCD < Test::Unit::TestCase
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: '0.3'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Dafydd Crosby
8
- autorequire:
7
+ - David Crosby
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-15 00:00:00.000000000 Z
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
- - .gitignore
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
- - bsd
28
- metadata: {}
29
- post_install_message:
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: '1.9'
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
- rubyforge_project:
45
- rubygems_version: 2.0.3
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: []