Class: BaseConvert::FromTo
- Inherits:
-
Object
- Object
- BaseConvert::FromTo
- Includes:
- BaseConvert, Configuration
- Defined in:
- lib/base_convert/from_to.rb
Constant Summary
Constants included from BaseConvert
Constants included from Configuration
Configuration::AMBIGUOUS, Configuration::BASE, Configuration::BASE64, Configuration::DIGITS, Configuration::GRAPH, Configuration::INDEXa, Configuration::QGRAPH, Configuration::UNAMBIGUOUS, Configuration::WORD, Configuration::WORD_
Instance Method Summary collapse
- #convert(counter) ⇒ Object (also: #[])
-
#initialize(base: 10, to_base: base, digits: WORD, to_digits: digits) ⇒ FromTo
constructor
A new instance of FromTo.
Methods included from BaseConvert
Constructor Details
#initialize(base: 10, to_base: base, digits: WORD, to_digits: digits) ⇒ FromTo
Returns a new instance of FromTo.
6 7 8 9 10 11 12 13 |
# File 'lib/base_convert/from_to.rb', line 6 def initialize(base: 10, to_base: base, digits: WORD, to_digits: digits) base = BASE[base] if base.is_a? Symbol to_base = BASE[to_base] if to_base.is_a? Symbol digits = DIGITS[digits] if digits.is_a? Symbol to_digits = DIGITS[to_digits] if to_digits.is_a? Symbol raise "base must cover digits." if base > digits.length or to_base > to_digits.length @base, @to_base, @digits, @to_digits = base, to_base, digits, to_digits end |
Instance Method Details
#convert(counter) ⇒ Object Also known as: []
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/base_convert/from_to.rb', line 15 def convert(counter) case counter when Integer tob(counter, @to_base, @to_digits) when String tob(toi(counter), @to_base, @to_digits) else raise "counter must be String|Integer." end end |