base_convert 2.0.0 → 2.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 +4 -4
- data/{README.rdoc → README.md} +30 -19
- data/lib/base_convert.rb +3 -1
- data/lib/base_convert/configuration.rb +11 -3
- metadata +10 -16
- data/lib/base_convert/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6257b71bda4550a74b03522240f2313a0033d6d8
|
4
|
+
data.tar.gz: 7cb3234969be8002ceccd826d631d8096b001b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 627175f20049ecea98ac7022e4fc737215a4068c1d3e1b211b4e1f6fe305fc6a139169a424b23b29c0b0016416e3484a0393cff4c046f3dff098542142491279
|
7
|
+
data.tar.gz: a1607a756ef907da773d40b9156cec8e0ad124e4ca0f92a72a0f79c334b03eaeb15580d24105d5957cb77ea8468a0c2615808657f44f57ae192f7680c60ee4e4
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
1
|
+
# BaseConvert
|
2
2
|
|
3
|
-
|
3
|
+
* [github](https://www.github.com/carlosjhr64/base_convert)
|
4
|
+
* [rubygems](https://rubygems.org/gems/base_convert)
|
4
5
|
|
5
|
-
|
6
|
-
rubygems :: https://rubygems.org/gems/base_convert
|
6
|
+
## DESCRIPTION:
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
base_convert - Number base conversion.
|
8
|
+
BaseConvert - Number base conversion.
|
11
9
|
|
12
10
|
Converts positive integers to different bases:
|
13
11
|
Binary, octal, hexadecimal, decimal, or any arbitrary base.
|
14
|
-
"Out of the box" handling of up to base
|
12
|
+
"Out of the box" handling of up to base 94.
|
15
13
|
Allows for arbitrary choice of alphabet(digits).
|
16
14
|
|
17
|
-
See also Non-
|
15
|
+
See also rosettacode.org's [Non-decimal radices convert](http://rosettacode.org/wiki/Non-decimal_radices/Convert).
|
18
16
|
|
19
|
-
|
17
|
+
## SYNOPSIS:
|
20
18
|
|
21
19
|
require 'base_convert'
|
22
20
|
include BaseConvert
|
@@ -25,7 +23,7 @@ See also Non-decimal_radices/Convert[http://rosettacode.org/wiki/Non-decimal_rad
|
|
25
23
|
a = h2o.convert('FFFF') #=> "177777"
|
26
24
|
b = o2h.convert('177777') #=> "FFFF"
|
27
25
|
|
28
|
-
|
26
|
+
## BUT WAIT, THERE'S MORE:
|
29
27
|
|
30
28
|
Using `irb` to demonstrate the features.
|
31
29
|
The components are scoped under `BaseConvert`:
|
@@ -53,9 +51,12 @@ You can work with arbitrary digits:
|
|
53
51
|
to_integer('&&&&', base, digits) #=> 4095
|
54
52
|
to_base(4095, base, digits) #=> "&&&&"
|
55
53
|
|
56
|
-
For convenience, `base_convert` provides
|
57
|
-
`
|
58
|
-
`QGRAPH` are the ASCII graph characters except quotes
|
54
|
+
For convenience, `base_convert` provides some predefined sets of digits.
|
55
|
+
`GRAPH` are the ASCII graph characters.
|
56
|
+
`QGRAPH` are the ASCII graph characters except quotes: double-quote, single-quote, and back-tick.
|
57
|
+
`WORD_` are the ASCII word characters including underscore(_).
|
58
|
+
`WORD` are the ASCII word characters except underscore(_).
|
59
|
+
`UNAMBIGUOUS` are the characters in `WORD` without the `AMBIGUOUS` characters(B8G6I1l0OQDS5Z2).
|
59
60
|
|
60
61
|
Configuration::WORD #=> "01...AB...ab...yz"
|
61
62
|
Configuration::QGRAPH #=> "!#...01...AB...ab...}~"
|
@@ -71,7 +72,7 @@ For example, to convert from hexadecimal to octal, and back:
|
|
71
72
|
o2h.convert('177777') #=> "FFFF"
|
72
73
|
|
73
74
|
You can access the conversion alphabets via
|
74
|
-
the accessors FromTo#from_digits and FromTo#to_digits
|
75
|
+
the accessors `FromTo#from_digits` and `FromTo#to_digits`.
|
75
76
|
By default, WORD is used for bases upto 62.
|
76
77
|
For bigger bases upto 91, QGRAPH is used.
|
77
78
|
You can have bigger bases, but
|
@@ -89,7 +90,6 @@ FromTo#base2integer and FromTo#integer2Base:
|
|
89
90
|
h2o.base2integer('FFFF') #=> 65535
|
90
91
|
h2o.integer2base(65535) #=> "177777"
|
91
92
|
|
92
|
-
The above replaces #base2dec and #dec2base which are now aliases and are deprecated.
|
93
93
|
The third way to convert is via the subclass of String, `BaseConvert::Number`:
|
94
94
|
|
95
95
|
hexadecimal = Number.new('FFFF', 16, Configuration::WORD) #=> "FFFF"
|
@@ -105,11 +105,22 @@ The third way to convert is via the subclass of String, `BaseConvert::Number`:
|
|
105
105
|
digits = ')!@#$%^&'
|
106
106
|
decimal.to_base(8, digits) #=> "!&&&&&"
|
107
107
|
|
108
|
-
|
108
|
+
## New in 2.1.0
|
109
|
+
|
110
|
+
# GRAPH.length == 94
|
111
|
+
# !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
112
|
+
|
113
|
+
# WORD_.length == 63
|
114
|
+
# 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
|
115
|
+
|
116
|
+
# UNAMBIGUOUS.length == 47
|
117
|
+
# 3479ACEFHJKLMNPRTUVWXYabcdefghijkmnopqrstuvwxyz
|
118
|
+
|
119
|
+
## INSTALL:
|
109
120
|
|
110
|
-
|
121
|
+
$ sudo gem install base_convert
|
111
122
|
|
112
|
-
|
123
|
+
## LICENSE:
|
113
124
|
|
114
125
|
(The MIT License)
|
115
126
|
|
data/lib/base_convert.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
module BaseConvert
|
2
2
|
module Configuration
|
3
3
|
|
4
|
-
|
4
|
+
GRAPH = 0.upto(255).map{|i| i.chr}.select{|c| c=~/[[:graph:]]/}.join.freeze
|
5
|
+
QGRAPH = GRAPH.delete(%('"`)).freeze
|
5
6
|
|
6
|
-
|
7
|
+
WORD_ = 0.upto(255).map{|i| i.chr}.select{|c| c=~/\w/}.join.freeze
|
8
|
+
WORD = WORD_.delete('_').freeze
|
7
9
|
INDEXa = WORD.index('a').freeze
|
8
10
|
|
11
|
+
AMBIGUOUS = 'B8G6I1l0OQDS5Z2'.freeze
|
12
|
+
UNAMBIGUOUS = WORD.delete(AMBIGUOUS).freeze
|
13
|
+
|
9
14
|
BASE = {
|
10
|
-
:
|
15
|
+
:graph => GRAPH.length,
|
11
16
|
:qgraph => QGRAPH.length,
|
17
|
+
:word_ => WORD_.length,
|
18
|
+
:word => WORD.length,
|
19
|
+
:unambiguous => UNAMBIGUOUS.length,
|
12
20
|
:hexadecimal => 16,
|
13
21
|
:hex => 16,
|
14
22
|
:decimal => 10,
|
metadata
CHANGED
@@ -1,44 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
|
-
|
14
|
+
BaseConvert - Number base conversion.
|
15
15
|
|
16
16
|
Converts positive integers to different bases:
|
17
17
|
Binary, octal, hexadecimal, decimal, or any arbitrary base.
|
18
|
-
"Out of the box" handling of up to base
|
18
|
+
"Out of the box" handling of up to base 94.
|
19
19
|
Allows for arbitrary choice of alphabet(digits).
|
20
20
|
email: carlosjhr64@gmail.com
|
21
21
|
executables: []
|
22
22
|
extensions: []
|
23
|
-
extra_rdoc_files:
|
24
|
-
- README.rdoc
|
23
|
+
extra_rdoc_files: []
|
25
24
|
files:
|
26
|
-
- README.
|
25
|
+
- README.md
|
27
26
|
- lib/base_convert.rb
|
28
27
|
- lib/base_convert/configuration.rb
|
29
28
|
- lib/base_convert/from_to.rb
|
30
29
|
- lib/base_convert/functions.rb
|
31
30
|
- lib/base_convert/helpers.rb
|
32
31
|
- lib/base_convert/number.rb
|
33
|
-
- lib/base_convert/version.rb
|
34
32
|
homepage: https://github.com/carlosjhr64/base_convert
|
35
33
|
licenses:
|
36
34
|
- MIT
|
37
35
|
metadata: {}
|
38
36
|
post_install_message:
|
39
|
-
rdoc_options:
|
40
|
-
- "--main"
|
41
|
-
- README.rdoc
|
37
|
+
rdoc_options: []
|
42
38
|
require_paths:
|
43
39
|
- lib
|
44
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -52,12 +48,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
48
|
- !ruby/object:Gem::Version
|
53
49
|
version: '0'
|
54
50
|
requirements:
|
55
|
-
- 'ruby: ruby 2.
|
56
|
-
- 'join: join (GNU coreutils) 8.21'
|
51
|
+
- 'ruby: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]'
|
57
52
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
53
|
+
rubygems_version: 2.6.13
|
59
54
|
signing_key:
|
60
55
|
specification_version: 4
|
61
|
-
summary:
|
56
|
+
summary: BaseConvert - Number base conversion.
|
62
57
|
test_files: []
|
63
|
-
has_rdoc:
|
data/lib/base_convert/version.rb
DELETED