Base62 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/Base62.rb +25 -4
  2. metadata +3 -3
@@ -1,8 +1,14 @@
1
1
  class Base62
2
-
3
- @@base = 62
4
- @@dictionary = nil
5
-
2
+ ##
3
+ # Converts a base 10 number to base 62
4
+ #
5
+ # ==== Attributes
6
+ #
7
+ # * +n_base10+ - Base 10 number to convert
8
+ #
9
+ # ==== Examples
10
+ #
11
+ # Base62.to_base62(123456789)
6
12
  def self.to_base62(n_base10)
7
13
  init_dictionary if @@dictionary.nil?
8
14
  result = ''
@@ -14,6 +20,16 @@ class Base62
14
20
  @@dictionary[n_base10] + result
15
21
  end
16
22
 
23
+ ##
24
+ # Converts a base 62 number to base 10
25
+ #
26
+ # ==== Attributes
27
+ #
28
+ # * +n_base62+ - Base 62 number to convert
29
+ #
30
+ # ==== Examples
31
+ #
32
+ # Base62.to_base10('AbCeF12345')
17
33
  def self.to_base10(n_base62)
18
34
  init_dictionary if @@dictionary.nil?
19
35
  result = 0
@@ -26,6 +42,11 @@ class Base62
26
42
  result
27
43
  end
28
44
 
45
+ private
46
+
47
+ @@base = 62
48
+ @@dictionary = nil
49
+
29
50
  def self.init_dictionary
30
51
  @@dictionary = [('0'..'9'),
31
52
  ('a'..'z'),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Base62
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,14 +11,14 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: A simple base62 converter
14
+ description: A simple base 10 <-> base 62 converter
15
15
  email: jorge.arrese@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/Base62.rb
21
- homepage: ''
21
+ homepage: https://github.com/j0rg/Base62
22
22
  licenses: []
23
23
  post_install_message:
24
24
  rdoc_options: []