radix_encoding 0.1.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -4
- data/lib/radix_encoding/encoding.rb +9 -3
- data/lib/radix_encoding/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4486ac5e941e55ee6ed097817f545c4d6f83b84f8e89ac815c9c5fef55e1351
|
4
|
+
data.tar.gz: 98101b65dbd73180c167542ed6d9977349e4009bead0b580e9a3c7dbd74da363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e1cb1778cb92d7db101a5f4dfff1f58956391c63b475861932a758c7aed84d5f90d0156c374bafddabd50c69f553305be057f15291a481517cd14cf87495b6
|
7
|
+
data.tar.gz: fe38b3bec27e1f104091a65d44c4fc7c5285d08e2d68d98de0bac6587779f5a8874511b61bc26615a861042bf82089d7eed733d2996b785c0f78aca0a1d9ad2a
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning].
|
|
10
10
|
Unreleased
|
11
11
|
----------
|
12
12
|
|
13
|
+
- Add optional parameter `prefix` to `Encoding`.
|
14
|
+
|
15
|
+
|
16
|
+
v0.1.0.1 - 2020-05-08
|
17
|
+
---------------------
|
18
|
+
|
13
19
|
- Change gem description to be clear we only support power-of-2 bases.
|
14
20
|
|
15
21
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,10 +43,9 @@ through constants under `RadixEncoding`:
|
|
43
43
|
To create your own encoding variant, use the `RadixEncoding::Encoding` class.
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
digest_hexencode = Encoding.new(
|
47
|
-
alphabet: "
|
48
|
-
radix:
|
49
|
-
padding: "=",
|
46
|
+
digest_hexencode = RadixEncoding::Encoding.new(
|
47
|
+
alphabet: "0123456789abcdef",
|
48
|
+
radix: 16,
|
50
49
|
)
|
51
50
|
```
|
52
51
|
|
@@ -15,17 +15,22 @@ module RadixEncoding
|
|
15
15
|
include EncodedPoints
|
16
16
|
include Validations
|
17
17
|
|
18
|
-
attr_reader :alphabet, :padding, :radix
|
18
|
+
attr_reader :alphabet, :padding, :prefix, :radix
|
19
19
|
|
20
|
-
def initialize(alphabet:, radix:, padding: nil)
|
20
|
+
def initialize(alphabet:, radix:, padding: nil, prefix: nil)
|
21
21
|
@alphabet = alphabet
|
22
22
|
@padding = padding
|
23
|
+
@prefix = prefix
|
23
24
|
@radix = radix
|
24
25
|
|
25
26
|
validate!
|
26
27
|
end
|
27
28
|
|
28
29
|
def decode(data)
|
30
|
+
if prefix.present? && data.start_with?(prefix)
|
31
|
+
data = data[prefix.size..-1]
|
32
|
+
end
|
33
|
+
|
29
34
|
decoded = data.chars
|
30
35
|
decoded = unpad_encoded_points(decoded)
|
31
36
|
decoded = bits_from_encoded_points(decoded)
|
@@ -63,7 +68,8 @@ module RadixEncoding
|
|
63
68
|
encoded = clean_encoded_points(encoded, padding_count)
|
64
69
|
encoded = pad_encoded_points(encoded, padding_count)
|
65
70
|
encoded = encoded.join
|
66
|
-
|
71
|
+
|
72
|
+
"#{prefix}#{encoded}"
|
67
73
|
end
|
68
74
|
|
69
75
|
def encoded_point_bitsize
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radix_encoding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|