Class: ChRad::Alphabet

Inherits:
Object
  • Object
show all
Defined in:
lib/chrad/alphabet.rb

Constant Summary collapse

B62 =
(
  ('A'..'Z').to_a +
  ('a'..'z').to_a +
  (0..9).to_a.map(&:to_s)
)
B32rfc =
(
  ('A'..'Z').to_a +
  ('2'..'7').to_a
)
B32 =
(
  ('0'..'9').to_a +
  ('a'..'v').to_a
)
B16 =
(
  ('0'..'9').to_a +
  ('a'..'f').to_a
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, digit_chars) ⇒ Alphabet

Returns a new instance of Alphabet.



54
55
56
57
58
# File 'lib/chrad/alphabet.rb', line 54

def initialize(name, digit_chars)
  @name = name
           
  self.digits = digit_chars
end

Instance Attribute Details

#digitsObject

Returns the value of attribute digits.



52
53
54
# File 'lib/chrad/alphabet.rb', line 52

def digits
  @digits
end

#nameObject (readonly)

Returns the value of attribute name.



52
53
54
# File 'lib/chrad/alphabet.rb', line 52

def name
  @name
end

Class Method Details

.[](name) ⇒ Object



36
37
38
# File 'lib/chrad/alphabet.rb', line 36

def self.[](name)
  find(name)
end

.add(name, digits) ⇒ Object



28
29
30
# File 'lib/chrad/alphabet.rb', line 28

def self.add(name, digits)
  all[name.to_s] = digits
end

.allObject



24
25
26
# File 'lib/chrad/alphabet.rb', line 24

def self.all
  @all ||= Hash.new
end

.find(name) ⇒ Object



32
33
34
# File 'lib/chrad/alphabet.rb', line 32

def self.find(name)
  all[name.to_s]
end

.namesObject



40
41
42
# File 'lib/chrad/alphabet.rb', line 40

def self.names
  all.keys
end

Instance Method Details

#[](*args) ⇒ Object



83
84
85
# File 'lib/chrad/alphabet.rb', line 83

def [](*args)
  digits[*args]
end

#lengthObject



87
88
89
# File 'lib/chrad/alphabet.rb', line 87

def length
  digits.length
end

#to_sObject



91
92
93
# File 'lib/chrad/alphabet.rb', line 91

def to_s
  digits.join('')
end