Class: Multibases::OrdTable

Inherits:
Object
  • Object
show all
Defined in:
lib/multibases/ord_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ords, strict:, padder: nil, encoding: nil) ⇒ OrdTable

Returns a new instance of OrdTable.



7
8
9
10
11
12
13
14
15
16
# File 'lib/multibases/ord_table.rb', line 7

def initialize(ords, strict:, padder: nil, encoding: nil)
  ords = ords.uniq

  @ords = ords
  @base = ords.length
  @padder = padder

  calculate_strictness(strict: strict)
  calculate_encoding(encoding: encoding)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



44
45
46
# File 'lib/multibases/ord_table.rb', line 44

def base
  @base
end

#encodingObject (readonly)

Returns the value of attribute encoding.



44
45
46
# File 'lib/multibases/ord_table.rb', line 44

def encoding
  @encoding
end

#factorObject (readonly)

Returns the value of attribute factor.



44
45
46
# File 'lib/multibases/ord_table.rb', line 44

def factor
  @factor
end

#padderObject (readonly)

Returns the value of attribute padder.



44
45
46
# File 'lib/multibases/ord_table.rb', line 44

def padder
  @padder
end

Instance Method Details

#alphabetObject



40
41
42
# File 'lib/multibases/ord_table.rb', line 40

def alphabet
  @ords.pack('C*')
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/multibases/ord_table.rb', line 18

def eql?(other)
  other.is_a?(OrdTable) &&
    other.alphabet == alphabet &&
    other.strict? == strict?
end

#hashObject



26
27
28
# File 'lib/multibases/ord_table.rb', line 26

def hash
  @ords.hash
end

#strict?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/multibases/ord_table.rb', line 30

def strict?
  @strict
end

#tr_ords(force_strict: false) ⇒ Object



34
35
36
37
38
# File 'lib/multibases/ord_table.rb', line 34

def tr_ords(force_strict: false)
  return @ords + [@padder].compact if strict? || force_strict

  @loose_ords + [@padder].compact
end