base58 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -3
- data/VERSION +1 -1
- data/base58.gemspec +2 -2
- data/lib/base58.rb +7 -1
- data/test/test_base58.rb +12 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -18,14 +18,14 @@ Base58 is hosted by http://gemcutter.com. Please make sure you have added them t
|
|
18
18
|
require 'base58'
|
19
19
|
|
20
20
|
# Int to Base58
|
21
|
-
Base58.
|
21
|
+
Base58.encode(12345) # => 4ER
|
22
22
|
|
23
23
|
# Base58 to Int
|
24
|
-
Base58.
|
24
|
+
Base58.decode('A2Ph') # => 6639914
|
25
25
|
|
26
26
|
== RDoc Documentation
|
27
27
|
|
28
|
-
You can view the rdoc documentation online[http://
|
28
|
+
You can view the rdoc documentation online[http://rdoc.info/projects/dougal/acts_as_indexed/].
|
29
29
|
|
30
30
|
== Problems, Comments, Suggestions?
|
31
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/base58.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{base58}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Douglas F Shearer"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-05}
|
13
13
|
s.description = %q{Base58 is a Ruby library for converting ints to and from base58.}
|
14
14
|
s.email = %q{dougal.s@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/base58.rb
CHANGED
@@ -12,7 +12,8 @@ class Base58
|
|
12
12
|
def self.base58_to_int(base58_val)
|
13
13
|
int_val = 0
|
14
14
|
base58_val.reverse.split(//).each_with_index do |char,index|
|
15
|
-
|
15
|
+
raise ArgumentError, 'Value passed not a valid Base58 String.' if (char_index = ALPHABET.index(char)).nil?
|
16
|
+
int_val += (char_index)*(BASE**(index))
|
16
17
|
end
|
17
18
|
int_val
|
18
19
|
end
|
@@ -29,4 +30,9 @@ class Base58
|
|
29
30
|
ALPHABET[int_val,1] + base58_val
|
30
31
|
end
|
31
32
|
|
33
|
+
class << self
|
34
|
+
alias_method :encode, :int_to_base58
|
35
|
+
alias_method :decode, :base58_to_int
|
36
|
+
end
|
37
|
+
|
32
38
|
end
|
data/test/test_base58.rb
CHANGED
@@ -521,4 +521,16 @@ EXAMPLES = { "6hKMCS" => 3471391110,
|
|
521
521
|
assert_equal 'Value passed is not an Integer.', e.message
|
522
522
|
end
|
523
523
|
|
524
|
+
def test_invalid_base58_string
|
525
|
+
e = assert_raise(ArgumentError) { Base58.base58_to_int('nh?') }
|
526
|
+
assert_equal 'Value passed not a valid Base58 String.', e.message
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_encode_decode_aliases
|
530
|
+
int = 3471844090
|
531
|
+
str = Base58.encode(int)
|
532
|
+
assert_equal str, "6hN7hS"
|
533
|
+
assert_equal int, Base58.decode(str)
|
534
|
+
end
|
535
|
+
|
524
536
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base58
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas F Shearer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-05 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|