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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '02197f59050cbbb957a0443cf736f694920b8d82f896e02bfeba3475f6d5a3af'
4
- data.tar.gz: 2a79111dac3bc6da8d8498e731df48f260c1cf417cbada372a37693f073595aa
3
+ metadata.gz: a4486ac5e941e55ee6ed097817f545c4d6f83b84f8e89ac815c9c5fef55e1351
4
+ data.tar.gz: 98101b65dbd73180c167542ed6d9977349e4009bead0b580e9a3c7dbd74da363
5
5
  SHA512:
6
- metadata.gz: b9b8e582773a4811ffb52512f984ea54e8b3076651b4c4dbf7c509885b521486f373f89f19ea5f762a8369344e37c910f42fbc617f8cebf57b0bb04e8c83ea6e
7
- data.tar.gz: fa5fb2cc3fe8203402fd08fb86a20869b36db1924be0add0a6441bebcc0ad263ab38e1687f25c488e014d6eed3be45290473167b8da17bf55a55caca7e10ea70
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- radix_encoding (0.1.0.1)
4
+ radix_encoding (0.2.0)
5
5
  activesupport (>= 3.0)
6
6
  subvisual-utils (~> 0.x)
7
7
 
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: "abcdefghijklmnopqrstuvwxyz234567",
48
- radix: 32,
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
- encoded
71
+
72
+ "#{prefix}#{encoded}"
67
73
  end
68
74
 
69
75
  def encoded_point_bitsize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RadixEncoding
4
- VERSION = "0.1.0.1"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.0.1
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-08 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport