Module: RadixEncoding::Encoding::EncodedPoints

Included in:
RadixEncoding::Encoding
Defined in:
lib/radix_encoding/encoding/encoded_points.rb

Instance Method Summary collapse

Instance Method Details

#alphabetObject

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 9

def alphabet
  raise NotImplementedError
end

#bits_from_encoded_points(encoded_points) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 23

def bits_from_encoded_points(encoded_points)
  encoded_points.
    map do |encoded_point|
      alphabet.
        index(encoded_point).
        to_s(2).
        rjust(encoded_point_bitsize, "0")
    end.
    join.
    chars
end

#clean_encoded_points(encoded_points, padding_size) ⇒ Object



13
14
15
16
17
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 13

def clean_encoded_points(encoded_points, padding_size)
  return encoded_points unless padding_size.positive?

  encoded_points[0...-padding_size]
end

#count_encoded_points_in(bitsize) ⇒ Object



19
20
21
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 19

def count_encoded_points_in(bitsize)
  bitsize / encoded_point_bitsize
end

#encoded_point_bitsizeObject

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 35

def encoded_point_bitsize
  raise NotImplementedError
end

#encoded_points_for(bits) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 39

def encoded_points_for(bits)
  bits.
    each_slice(encoded_point_bitsize).
    map do |encoded_point_bits|
      encoded_point_index = encoded_point_bits.join.to_i(2)

      alphabet[encoded_point_index]
    end
end

#pad_encoded_points(encoded_points, padding_size) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 49

def pad_encoded_points(encoded_points, padding_size)
  return encoded_points if padding.blank?

  padded_size = encoded_points.size + padding_size

  Subvisual::ArrayUtils.pad_right(encoded_points, padded_size, padding)
end

#paddingObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 57

def padding
  raise NotImplementedError
end

#unpad_encoded_points(encoded_points) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/radix_encoding/encoding/encoded_points.rb', line 61

def unpad_encoded_points(encoded_points)
  first_padding_index = encoded_points.index(padding)

  return encoded_points if first_padding_index.nil?

  encoded_points[0...first_padding_index]
end