integer-base 0.1.1 → 0.1.2

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
2
  SHA256:
3
- metadata.gz: f369f7708ab4ad8a5984a4202b74953a13d65c4f5ebc55b4a934735bdf72dacc
4
- data.tar.gz: 64d303a8849d3f93eeaf5f98af17fe251a251ee987daf4ce6d1812f8fe379aca
3
+ metadata.gz: c4314c81f697b872b1c6e1123918a2d461e8dafd0ad5bf330fb8a3605e8c4a65
4
+ data.tar.gz: de72e33b21c53d2c5ce7bbced3c733be15c36c89df27f90ccfe4dcc9ed1dcbe1
5
5
  SHA512:
6
- metadata.gz: f1aaef4b2286e9166b5e1863cd8b51e83d682b6383959316714f425601cdfa0224acc4cf60dde1cacb6861072cd9cf879f79543356c432dc4b5b887473f6149a
7
- data.tar.gz: 7c75bae3fd656f49fd74918109a3ec3adce31fcbcd7353305562ba0735e1651fb8df81c80c394eac2213a4893c6aa3dc183f226a6f2af8c1e568453b2269fbff
6
+ metadata.gz: 04ad0b11cfeab609d3438c8ad856df92d3480bad89c4e698a1a9e2586fb05b5476fcaa6639c9c810b31a439adf570bb4592efad3aa1e98763bd072e7b1166421
7
+ data.tar.gz: e729ed60074637eaee101e12bd931936a3925ee34b03914a8e4fd81b8340236949e02c4f170e829e58c3b0c1aeeedf3afdf4d3b6e2c35c9975386ed9bd8eb443
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
@@ -0,0 +1,21 @@
1
+ name: Testing workflow
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest]
9
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
+ # Don't include `truffleruby` and `jruby`
11
+ # * https://github.com/kachick/integer-base/runs/2426555099
12
+ # * https://github.com/kachick/integer-base/runs/2426555119
13
+ ruby: [2.5, 2.6, 2.7, '3.0', head]
14
+ runs-on: ${{ matrix.os }}
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
21
+ - run: bundle exec rake
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  integer-base
2
2
  =============
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/kachick/integer-base.png)](http://travis-ci.org/kachick/integer-base)
4
+ ![Build Status](https://github.com/kachick/integer-base/actions/workflows/test.yml/badge.svg?branch=main)
5
5
  [![Gem Version](https://badge.fury.io/rb/integer-base.png)](http://badge.fury.io/rb/integer-base)
6
6
 
7
7
  Description
@@ -53,7 +53,7 @@ using Integer::Base
53
53
  Requirements
54
54
  -------------
55
55
 
56
- * [Ruby 2.5 or later](http://travis-ci.org/#!/kachick/integer-base)
56
+ * Ruby 2.5 or later
57
57
 
58
58
  Install
59
59
  -------
@@ -65,11 +65,7 @@ $ gem install integer-base
65
65
  Link
66
66
  ----
67
67
 
68
- * [code](https://github.com/kachick/integer-base)
69
- * [API](http://www.rubydoc.info/github/kachick/integer-base)
70
- * [issues](https://github.com/kachick/integer-base/issues)
71
- * [CI](http://travis-ci.org/#!/kachick/integer-base)
72
- * [gem](https://rubygems.org/gems/integer-base)
68
+ * [API documentation](https://rubydoc.info/github/kachick/integer-base/)
73
69
 
74
70
  License
75
71
  --------
data/integer-base.gemspec CHANGED
@@ -1,34 +1,32 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
- lib_name = 'integer-base'.freeze
4
+ lib_name = 'integer-base'
4
5
 
5
6
  require File.expand_path('../lib/integer/base/version', __FILE__)
6
7
 
7
8
  Gem::Specification.new do |gem|
8
9
  gem.authors = ['Kenichi Kamiya']
9
10
  gem.email = ['kachick1+ruby@gmail.com']
11
+ gem.summary = %q{Any formats can mean positional/unary numeral systems}
10
12
  gem.description = %q{Any formats can mean positional/unary numeral systems :)
11
- So base number conversion under your choise.}
12
- gem.summary = %q{Any formats can mean positional/unary numeral systems :)}
13
+ So base number conversion under your choice.}
13
14
 
14
- gem.summary = gem.description.dup
15
15
  gem.homepage = "https://github.com/kachick/#{lib_name}"
16
16
  gem.license = 'MIT'
17
- gem.name = lib_name.dup
18
- # dup for https://github.com/rubygems/rubygems/commit/48f1d869510dcd325d6566df7d0147a086905380#-P0
19
- gem.version = Integer::Base::VERSION.dup
17
+ gem.name = lib_name
18
+ gem.version = Integer::Base::VERSION
20
19
 
21
- gem.add_development_dependency 'test-unit', '>= 3.3.3', '< 4'
22
- gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
23
- gem.add_development_dependency 'rake', '>= 10', '< 20'
24
- gem.add_development_dependency 'bundler', '>= 2', '< 3'
20
+ gem.add_development_dependency 'test-unit', '>= 3.4.1', '< 4'
21
+ gem.add_development_dependency 'yard', '>= 0.9.26', '< 2'
22
+ gem.add_development_dependency 'rake', '>= 13.0.3', '< 20'
25
23
 
24
+ gem.required_ruby_version = '>= 2.5'
25
+
26
26
  # common
27
27
 
28
28
  gem.authors = ['Kenichi Kamiya']
29
29
  gem.email = ['kachick1+ruby@gmail.com']
30
30
  gem.files = `git ls-files`.split($\)
31
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
32
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
33
31
  gem.require_paths = ['lib']
34
32
  end
data/lib/integer/base.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
  # Copyright (C) 2011 Kenichi Kamiya
3
4
 
4
5
  class Integer
@@ -31,6 +32,10 @@ class Integer
31
32
  standards[:BINARY] = standards[2]
32
33
  }.freeze
33
34
 
35
+ # Crockford's Base32. Excluded I, L, O, U.
36
+ # @see https://www.crockford.com/base32.html
37
+ ENCODED_CROCKFORD_BASE32_CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'.chars.map(&:to_sym).freeze
38
+
34
39
  end
35
40
 
36
41
  end
@@ -1,4 +1,5 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
4
  class Integer; module Base
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
4
  class Integer; module Base
4
5
 
@@ -47,7 +48,7 @@ class Integer; module Base
47
48
 
48
49
  if sign
49
50
  if str.empty?
50
- raise InvalidCharacterError
51
+ raise InvalidCharacterError, 'given string does not have characters except +/-'
51
52
  else
52
53
  sign.to_sym
53
54
  end
@@ -65,7 +66,7 @@ class Integer; module Base
65
66
  when chars.length < 2
66
67
  raise TypeError, 'use 2 or more than characters'
67
68
  when chars.dup.uniq!
68
- raise InvalidCharacterError, 'dupulicated characters'
69
+ raise InvalidCharacterError, 'duplicated characters'
69
70
  when chars.any?{|s|s.length != 1}
70
71
  raise InvalidCharacterError,
71
72
  'chars must be Array<Char> (Char: length 1)'
@@ -80,7 +81,7 @@ class Integer; module Base
80
81
  # @return [Symbol]
81
82
  def unary_char_for(char)
82
83
  unless (char.length == 1) and char.respond_to?(:to_sym)
83
- raise InvalidCharacterError, char
84
+ raise InvalidCharacterError, "#{char.inspect} must be 1 character and can be symbolized"
84
85
  end
85
86
 
86
87
  char.to_sym
@@ -92,7 +93,7 @@ class Integer; module Base
92
93
 
93
94
  # @return [Integer]
94
95
  def parse_positional_abs(str, chars)
95
- raise InvalidCharacterError if str.empty?
96
+ raise InvalidCharacterError, 'given str is empty' if str.empty?
96
97
  base = chars.length
97
98
  chars = base_chars_for chars
98
99
 
@@ -105,7 +106,7 @@ class Integer; module Base
105
106
  if radix = chars.index(char.to_sym)
106
107
  sum + (radix * (base ** index))
107
108
  else
108
- raise InvalidCharacterError
109
+ raise InvalidCharacterError, "#{char} is not defined on #{chars}"
109
110
  end
110
111
  }
111
112
  end
@@ -138,7 +139,7 @@ class Integer; module Base
138
139
 
139
140
  return chars.first.to_s if int == 0
140
141
 
141
- ''.tap {|s|
142
+ (+'').tap {|s|
142
143
  n = int.abs
143
144
 
144
145
  until (n, excess = n.divmod base; n == 0 && excess == 0)
@@ -1,7 +1,8 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
4
  class Integer; module Base
4
5
 
5
- VERSION = '0.1.1'.freeze
6
+ VERSION = '0.1.2'
6
7
 
7
8
  end; end
@@ -162,4 +162,11 @@ class TestIntegerBase < Test::Unit::TestCase
162
162
  assert_equal(73, '1!'.to_i([*Integer::Base::STANDARD_CHARS[36], '!']))
163
163
  end
164
164
 
165
+ def test_typical_crockford_base32
166
+ # ULID examples
167
+ assert_equal(340282366920938463463374607431768211455, Integer::Base.parse('7ZZZZZZZZZZZZZZZZZZZZZZZZZ', Integer::Base::ENCODED_CROCKFORD_BASE32_CHARS))
168
+ assert_equal('7ZZZZZZZZZZZZZZZZZZZZZZZZZ'.downcase, Integer::Base.string_for(340282366920938463463374607431768211455, Integer::Base::ENCODED_CROCKFORD_BASE32_CHARS))
169
+ # Not yet supported aliases, I i L l as 1
170
+ end
171
+
165
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integer-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-04 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.3.3
19
+ version: 3.4.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 3.3.3
29
+ version: 3.4.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.9.20
39
+ version: 0.9.26
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.9.20
49
+ version: 0.9.26
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2'
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '10'
59
+ version: 13.0.3
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '20'
@@ -66,41 +66,22 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '10'
69
+ version: 13.0.3
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '20'
73
- - !ruby/object:Gem::Dependency
74
- name: bundler
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '2'
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '3'
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '2'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: '3'
93
73
  description: |-
94
74
  Any formats can mean positional/unary numeral systems :)
95
- So base number conversion under your choise.
75
+ So base number conversion under your choice.
96
76
  email:
97
77
  - kachick1+ruby@gmail.com
98
78
  executables: []
99
79
  extensions: []
100
80
  extra_rdoc_files: []
101
81
  files:
82
+ - ".github/dependabot.yml"
83
+ - ".github/workflows/test.yml"
102
84
  - ".gitignore"
103
- - ".travis.yml"
104
85
  - ".yardopts"
105
86
  - Gemfile
106
87
  - LICENSE
@@ -118,7 +99,7 @@ homepage: https://github.com/kachick/integer-base
118
99
  licenses:
119
100
  - MIT
120
101
  metadata: {}
121
- post_install_message:
102
+ post_install_message:
122
103
  rdoc_options: []
123
104
  require_paths:
124
105
  - lib
@@ -126,19 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
107
  requirements:
127
108
  - - ">="
128
109
  - !ruby/object:Gem::Version
129
- version: '0'
110
+ version: '2.5'
130
111
  required_rubygems_version: !ruby/object:Gem::Requirement
131
112
  requirements:
132
113
  - - ">="
133
114
  - !ruby/object:Gem::Version
134
115
  version: '0'
135
116
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.7.6
138
- signing_key:
117
+ rubygems_version: 3.2.15
118
+ signing_key:
139
119
  specification_version: 4
140
- summary: Any formats can mean positional/unary numeral systems :) So base number conversion
141
- under your choise.
142
- test_files:
143
- - test/helper.rb
144
- - test/test_integer-base.rb
120
+ summary: Any formats can mean positional/unary numeral systems
121
+ test_files: []
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - ruby-head
5
- - 2.6
6
- - 2.5
7
- - rbx-3
8
- - jruby-head
9
-
10
- matrix:
11
- allow_failures:
12
- - rvm: ruby-head
13
- - rvm: rbx-3
14
- - rvm: jruby-head
15
-
16
- before_install:
17
- - gem install bundler