Class: ChRad::IOManager
- Inherits:
-
Object
show all
- Defined in:
- lib/chrad/io_manager.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
5
6
7
|
# File 'lib/chrad/io_manager.rb', line 5
def base
@base
end
|
#digits ⇒ Object
Returns the value of attribute digits.
7
8
9
|
# File 'lib/chrad/io_manager.rb', line 7
def digits
@digits
end
|
#mode ⇒ Object
9
10
11
|
# File 'lib/chrad/io_manager.rb', line 9
def mode
@mode ||= DEFAULT_MODE
end
|
#separator ⇒ Object
24
25
26
|
# File 'lib/chrad/io_manager.rb', line 24
def separator
@separator ||= DEFAULT_SEPARATOR
end
|
#stream ⇒ Object
Returns the value of attribute stream.
5
6
7
|
# File 'lib/chrad/io_manager.rb', line 5
def stream
@stream
end
|
Instance Method Details
#alphabet ⇒ Object
28
29
30
|
# File 'lib/chrad/io_manager.rb', line 28
def alphabet
@alphabet ||= DEFAULT_ALPHABET
end
|
#alphabet=(str) ⇒ Object
32
33
34
|
# File 'lib/chrad/io_manager.rb', line 32
def alphabet=(str)
@alphabet = automagic_find_alphabet(str)
end
|
#automagic_find_alphabet(str) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/chrad/io_manager.rb', line 36
def automagic_find_alphabet(str)
case str
when /\Aname:(\w+)\Z/
Alphabet.find($1) or raise Error, "No digit alphabet named \"#{$1}\""
else
Alphabet.new("custom_#{name}", str)
end
end
|
#setup_base_digits! ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/chrad/io_manager.rb', line 45
def setup_base_digits!
case mode
when :alphabet
if base > alphabet.length
raise Error, "Trying to use base #{base}, but the input alphabet only has #{alphabet.length} characters."
end
@digits = alphabet[0, base]
when :list
else
raise Error, "Invalid mode #{mode.inspect}"
end
end
|
#value_to_digit(value) ⇒ Object
62
63
64
65
|
# File 'lib/chrad/io_manager.rb', line 62
def value_to_digit(value)
raise Error, '@digits == nil' if @digits.nil?
@digits[value]
end
|