Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ipxact/ruby_ext/string.rb
Instance Method Summary collapse
-
#base ⇒ Fixnum
Returns base of number represented by this string e.g.
-
#to_dec ⇒ Fixnum
Returns numerical value of string in decimal form.
Instance Method Details
#base ⇒ Fixnum
Returns base of number represented by this string e.g. â0x0Fâ => 16
11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 ⇒ Fixnum
Returns numerical value of string in decimal form
25 26 27 28 29 30 31 32 33 |
# 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 |