Class: Nio::DigitsDef

Inherits:
Object
  • Object
show all
Includes:
StateEquivalent
Defined in:
lib/nio/repdec.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StateEquivalent

#==, #===, #eql?, #hash

Constructor Details

#initialize(ds = '0123456789', cs = true) ⇒ DigitsDef

Returns a new instance of DigitsDef.



18
19
20
21
22
23
# File 'lib/nio/repdec.rb', line 18

def initialize(ds='0123456789', cs=true)
  @digits = ds
  @casesens = cs
  @dncase = (ds.downcase==ds)
  @radix = @digits.size
end

Class Method Details

.base(b, dncase = false, casesens = false) ⇒ Object



41
42
43
44
45
# File 'lib/nio/repdec.rb', line 41

def DigitsDef.base(b,dncase=false,casesens=false)
  dgs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[0,b]
  dgs.downcase! if dncase
  DigitsDef.new(dgs,casesens)
end

Instance Method Details

#digit_char(v) ⇒ Object



32
33
34
# File 'lib/nio/repdec.rb', line 32

def digit_char(v)
  @digits[v]
end

#digit_char_safe(v) ⇒ Object



35
36
37
# File 'lib/nio/repdec.rb', line 35

def digit_char_safe(v)
  v>=0 && v<@radix ? @digits[v] : nil
end

#digit_value(ch_code) ⇒ Object



28
29
30
31
# File 'lib/nio/repdec.rb', line 28

def digit_value(ch_code)
  ch_code = set_case(ch_code) unless @casesens
  @digits.index(ch_code.chr)
end

#is_digit?(ch_code) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/nio/repdec.rb', line 24

def is_digit?(ch_code)
  ch_code = set_case(ch_code) unless @casesens
  @digits.include?(ch_code)
end

#radixObject



38
39
40
# File 'lib/nio/repdec.rb', line 38

def radix
  @radix
end