class String

Public Instance Methods

base() click to toggle source

@return [Fixnum] returns base of number represented by this string e.g. '0x0F' => 16

# File lib/ipxact/ruby_ext/string.rb, line 11
def base
  case self
    when PREFIX_BIN, POSTFIX_BIN
      2
    when PREFIX_HEX, POSTFIX_HEX, NAKED_HEX
      16
    when DECIMAL
      10
    else
      nil
  end
end
to_dec() click to toggle source

@return [Fixnum] returns numerical value of string in decimal form

# File lib/ipxact/ruby_ext/string.rb, line 25
def to_dec
  case self
    when PREFIX_BIN, PREFIX_HEX   then self[2..-1]
    when POSTFIX_HEX, POSTFIX_BIN then self[0..-2]
    when DECIMAL, NAKED_HEX       then self
    else
      raise Exception, "'#{self}' is not a numerical string!"
  end.to_i(base)
end