Class: Multibases::OrdTable
- Inherits:
-
Object
- Object
- Multibases::OrdTable
- Defined in:
- lib/multibases/ord_table.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#factor ⇒ Object
readonly
Returns the value of attribute factor.
-
#padder ⇒ Object
readonly
Returns the value of attribute padder.
Instance Method Summary collapse
- #alphabet ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(ords, strict:, padder: nil, encoding: nil) ⇒ OrdTable
constructor
A new instance of OrdTable.
- #strict? ⇒ Boolean
- #tr_ords(force_strict: false) ⇒ Object
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
44 45 46 |
# File 'lib/multibases/ord_table.rb', line 44 def base @base end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
44 45 46 |
# File 'lib/multibases/ord_table.rb', line 44 def encoding @encoding end |
#factor ⇒ Object (readonly)
Returns the value of attribute factor.
44 45 46 |
# File 'lib/multibases/ord_table.rb', line 44 def factor @factor end |
#padder ⇒ Object (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
#alphabet ⇒ Object
40 41 42 |
# File 'lib/multibases/ord_table.rb', line 40 def alphabet @ords.pack('C*') end |
#eql?(other) ⇒ Boolean Also known as: ==
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 |
#hash ⇒ Object
26 27 28 |
# File 'lib/multibases/ord_table.rb', line 26 def hash @ords.hash end |
#strict? ⇒ 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 |