anybase 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/anybase.rb +5 -2
  3. data/spec/to_spec.rb +11 -0
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/anybase.rb CHANGED
@@ -28,14 +28,17 @@ class Anybase
28
28
  num
29
29
  end
30
30
 
31
- def to_native(val)
31
+ def to_native(val, options = nil)
32
32
  str = ''
33
33
  until val.zero?
34
34
  digit = val % chars.size
35
35
  val /= chars.size
36
36
  str[0, 0] = @num_map[digit]
37
37
  end
38
- str
38
+ if options && options[:zero_pad]
39
+ str[0, 0] = @num_map[0] * (options[:zero_pad] - str.size)
40
+ end
41
+ str == '' ? @num_map[0].dup : str
39
42
  end
40
43
 
41
44
  Hex = Anybase.new('0123456789abcdef', :ignore_case => true)
data/spec/to_spec.rb CHANGED
@@ -5,4 +5,15 @@ describe Anybase, "to" do
5
5
  it "should translate base to a number from a string " do
6
6
  Anybase.new("012345678").to_native(1827).should == "2450"
7
7
  end
8
+
9
+ it "should never return an empty string for 0" do
10
+ Anybase.new("012345678").to_native(0).should == "0"
11
+ end
12
+
13
+ it "should zeropad" do
14
+ result = Anybase.new("012345678").to_native(1234, :zero_pad => 8)
15
+ result.size.should == 8
16
+ result.should == '00001621'
17
+ end
18
+
8
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anybase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-03 00:00:00 -05:00
12
+ date: 2009-12-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15