Module: BaseConvert
- Extended by:
- BaseConvert
- Included in:
- BaseConvert, FromTo, Number
- Defined in:
- lib/base_convert/base_convert.rb,
lib/base_convert.rb,
lib/base_convert/number.rb,
lib/base_convert/from_to.rb,
lib/base_convert/configuration.rb
Overview
Defined Under Namespace
Constant Summary collapse
- VERSION =
'3.1.191231'- QUOTES =
%("'`).freeze
- UNDERSCORE =
'_'.freeze
- AMBIGUOUS =
'B8G6I1l0OQDS5Z2'.freeze
- GRAPH =
0.upto(255).map{|i| i.chr}.select{|c| c=~/[[:graph:]]/}.join.freeze
- QGRAPH =
GRAPH.delete(QUOTES).freeze
- WORD_ =
QGRAPH.chars.select{|c| c=~/\w/}.join.freeze
- WORD =
WORD_.delete(UNDERSCORE).freeze
- UNAMBIGUOUS =
WORD.delete(AMBIGUOUS).freeze
- G94 =
(WORD + QGRAPH.delete(WORD_) + QUOTES + UNDERSCORE).freeze
- BASE64 =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.freeze
- INDEXa =
G94.index('a')
- BASE =
{ :g94 => G94.length, # 94 :graph => GRAPH.length, # 94 :qgraph => QGRAPH.length, # 91 :word_ => WORD_.length, # 63 :word => WORD.length, # 62 :unambiguous => UNAMBIGUOUS.length, # 47 :base64 => 64, :b64 => 64, :hexadecimal => 16, :hex => 16, :h => 16, :decimal => 10, :dec => 10, :d => 10, :octal => 8, :oct => 8, :o => 8, :binary => 2, :bin => 2, :b => 2, }
- DIGITS =
{ :g94 => G94, :graph => GRAPH, :g => GRAPH, :qgraph => QGRAPH, :q => QGRAPH, :word_ => WORD_, :w_ => WORD_, :word => WORD, :w => WORD, :unambiguous => UNAMBIGUOUS, :u => UNAMBIGUOUS, :base64 => BASE64, :b64 => BASE64, }
Instance Method Summary collapse
- #tob(integer = @integer, base = @base, digits = @digits) ⇒ Object
- #toi(string = @string, base = @base, digits = @digits) ⇒ Object
Instance Method Details
#tob(integer = @integer, base = @base, digits = @digits) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/base_convert/base_convert.rb', line 12 def tob(integer=@integer, base=@base, digits=@digits) return digits[0] if integer == 0 string = '' while integer > 0 integer, index = integer.divmod(base) string = string.insert(0, digits[index]) end string end |
#toi(string = @string, base = @base, digits = @digits) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/base_convert/base_convert.rb', line 3 def toi(string=@string, base=@base, digits=@digits) integer = 0 string.each_char do |c| index = digits.index(c) integer = integer * base + index end integer end |