Module: Shorten::String
- Included in:
- String
- Defined in:
- lib/shorten.rb
Instance Method Summary collapse
-
#unshorten(chars = Shorten::BASE62) ⇒ Fixnum/Bignum
Unshortened number.
Instance Method Details
#unshorten(chars = Shorten::BASE62) ⇒ Fixnum/Bignum
Returns Unshortened number.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shorten.rb', line 29 def unshorten chars = Shorten::BASE62 raise ArgumentError.new('String required') unless chars.is_a? String num = 0 len = chars.length self.each_char do |c| num *= len char = chars.index(c) raise ArgumentError.new('Cannot unshorten: invalid characters') if char.nil? num += char end num end |