anybase 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0a553c5494e6bec8b36fe351538873d77a6649b
4
+ data.tar.gz: dabf637b3b92b006fe73ccbd94fe3c39933f68b4
5
+ SHA512:
6
+ metadata.gz: 8d9a45c0289ff82c8ce0630279bfc54322ae29f7a089ee29f7b0ca3ab8294447afebb93174fefbc224c355685b5f248b9da03ef138f75b188ae1fbe1ebc1eaca
7
+ data.tar.gz: 870ceff52e3ad3d304af5eae2cc1aac33327389f474f61ccaf8a3460117e55cfda4d1ff616d7cc95383aa0b27c037170c84873a75f58a89222b2a4bcac65fa58
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-2
9
+
10
+ # Force build to be use Travis' newer container-based builds, which seem
11
+ # more reliable.
12
+ # https://docs.travis-ci.com/user/workers/container-based-infrastructure/#Routing-your-build-to-container-based-infrastructure
13
+ sudo: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in anybase.gemspec
4
- gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -5,4 +5,6 @@ desc "Run specs"
5
5
  RSpec::Core::RakeTask.new do |t|
6
6
  t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
7
7
  # Put spec opts in a file named .rspec in root
8
- end
8
+ end
9
+
10
+ task :default => [:spec]
@@ -21,4 +21,4 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "rake"
24
- end
24
+ end
@@ -1,4 +1,5 @@
1
1
  require "anybase/version"
2
+ require "securerandom"
2
3
 
3
4
  class Anybase
4
5
 
@@ -24,7 +25,7 @@ class Anybase
24
25
  add_mapping(c, i)
25
26
  @num_map[i] = c
26
27
  if @synonyms && @synonyms[c]
27
- @synonyms[c].split('').each { |sc|
28
+ @synonyms[c].split('').each { |sc|
28
29
  regexp_str << Regexp.quote(sc)
29
30
  @synonyms_tr[1] << c
30
31
  @synonyms_tr[0] << sc
@@ -46,11 +47,11 @@ class Anybase
46
47
  def ignore_case?
47
48
  @ignore_case
48
49
  end
49
-
50
+
50
51
  def size(digits)
51
52
  chars.length ** digits
52
53
  end
53
-
54
+
54
55
  def normalize(val)
55
56
  val = val.downcase if ignore_case?
56
57
  @synonyms ? val.tr(*@synonyms_tr) : val
@@ -59,14 +60,14 @@ class Anybase
59
60
  def random(digits, opts = nil)
60
61
  zero_pad = opts && opts.key?(:zero_pad) ? opts[:zero_pad] : true
61
62
  number = ''
62
- digits.times { number << chars[rand(chars.size)]}
63
+ digits.times { number << chars[SecureRandom.random_number(chars.size)]}
63
64
  unless zero_pad
64
65
  number.sub!(/\A#{Regexp.quote(chars[0].chr)}+/, '')
65
66
  number = chars[0].chr if number.empty?
66
67
  end
67
68
  number
68
69
  end
69
-
70
+
70
71
  def to_i(val)
71
72
  val = normalize(val)
72
73
  op = if @sign and val[0] == @sign[0]
@@ -1,3 +1,3 @@
1
1
  class Anybase
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
@@ -2,30 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Anybase, "from" do
4
4
  it "should translate to a number" do
5
- Anybase.new("012345678").to_i('2350').should == 1746
5
+ expect(Anybase.new("012345678").to_i('2350')).to eq(1746)
6
6
  end
7
7
 
8
8
  it "should raise an exception if any char isn't included" do
9
- proc { Anybase.new("012345678").to_i('a2350') }.should raise_error(Anybase::UnrecognizedCharacterError)
9
+ expect { Anybase.new("012345678").to_i('a2350') }.to raise_error(Anybase::UnrecognizedCharacterError)
10
10
  end
11
11
 
12
12
  it "should fold case" do
13
13
  base = Anybase.new("012345678abcd", :ignore_case => true)
14
14
  str = 'a23D5d0AbBc'
15
- base.to_i(str).should == base.to_i(str.swapcase)
15
+ expect(base.to_i(str)).to eq(base.to_i(str.swapcase))
16
16
  end
17
17
 
18
18
  it "should translate negative numbers with a sign" do
19
- Anybase.new("012345678", :sign => '9').to_i('911').should == -10
19
+ expect(Anybase.new("012345678", :sign => '9').to_i('911')).to eq(-10)
20
20
  end
21
21
 
22
22
  it "should use synonymous" do
23
- Anybase.new("012345678", :synonyms => {'0' => 'oO'}).to_i('O235o').should == 1746
24
- proc { Anybase.new("012345678", :synonyms => {'0' => 'o'}).to_i('235O') }.should raise_error(Anybase::UnrecognizedCharacterError)
23
+ expect(Anybase.new("012345678", :synonyms => {'0' => 'oO'}).to_i('O235o')).to eq(1746)
24
+ expect { Anybase.new("012345678", :synonyms => {'0' => 'o'}).to_i('235O') }.to raise_error(Anybase::UnrecognizedCharacterError)
25
25
  end
26
26
 
27
27
  it "should use synonymous & ignore case" do
28
- Anybase.new("012345678", :synonyms => {'0' => 'o'}, :ignore_case => true).to_i('235O').should == 1746
28
+ expect(Anybase.new("012345678", :synonyms => {'0' => 'o'}, :ignore_case => true).to_i('235O')).to eq(1746)
29
29
  end
30
30
 
31
31
  end
@@ -1,4 +1,4 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'rspec'
4
- require 'anybase'
4
+ require 'anybase'
@@ -2,42 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  describe Anybase, "to" do
4
4
  it "should translate base to a number from a string " do
5
- Anybase.new("012345678").to_native(1827).should == "2450"
5
+ expect(Anybase.new("012345678").to_native(1827)).to eq("2450")
6
6
  end
7
7
 
8
8
  it "should never return an empty string for 0" do
9
- Anybase.new("012345678").to_native(0).should == "0"
9
+ expect(Anybase.new("012345678").to_native(0)).to eq("0")
10
10
  end
11
11
 
12
12
  it "should normally raise on negative numbers" do
13
- proc { Anybase.new("012345678").to_native(-10)}.should raise_error
13
+ expect { Anybase.new("012345678").to_native(-10)}.to raise_error(RuntimeError)
14
14
  end
15
15
 
16
16
  it "should translate negative numbers with a sign" do
17
- Anybase.new("012345678", :sign => '9').to_native(-10).should == '911'
17
+ expect(Anybase.new("012345678", :sign => '9').to_native(-10)).to eq('911')
18
18
  end
19
19
 
20
20
  it "should zeropad" do
21
- Anybase.new("012345678").to_native(1234, :zero_pad => 2).should == '1621'
22
- Anybase.new("012345678").to_native(1234, :zero_pad => 4).should == '1621'
23
- Anybase.new("012345678").to_native(1234, :zero_pad => 8).should == '00001621'
21
+ expect(Anybase.new("012345678").to_native(1234, :zero_pad => 2)).to eq('1621')
22
+ expect(Anybase.new("012345678").to_native(1234, :zero_pad => 4)).to eq('1621')
23
+ expect(Anybase.new("012345678").to_native(1234, :zero_pad => 8)).to eq('00001621')
24
24
  end
25
25
 
26
26
  it "create random numbers" do
27
- srand(10)
27
+ allow(SecureRandom).to receive(:random_number).and_return(5,4,3,2,1,0)
28
28
  result = Anybase.new("012345678").random(10)
29
- result.should == '4010180864'
29
+ expect(result).to eq('5432100000')
30
30
 
31
- srand(39)
32
- Anybase.new("012345678").random(10, :zero_pad => false).should == '463048140'
31
+ allow(SecureRandom).to receive(:random_number).and_return(0,0,1,2,3,4,5)
32
+ expect(Anybase.new("012345678").random(10, :zero_pad => false)).to eq('12345555')
33
33
  end
34
34
 
35
35
  it "return a zero if thats all it can for a random number" do
36
36
  result = Anybase.new("0").random(10)
37
- result.should == '0000000000'
37
+ expect(result).to eq('0000000000')
38
38
 
39
39
  result = Anybase.new("0").random(10, :zero_pad => false)
40
- result.should == '0'
40
+ expect(result).to eq('0')
41
41
  end
42
42
 
43
43
  end
@@ -2,22 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe Anybase, "util" do
4
4
  it "should tell you the size for an arbitrary number of digits" do
5
- Anybase.new("012345678").size(10).should == 3486784401
6
- (Anybase.new("012345678").size(10) * Anybase.new("012345678").size(10)).should == Anybase.new("012345678").size(20)
5
+ expect(Anybase.new("012345678").size(10)).to eq(3486784401)
6
+ expect(Anybase.new("012345678").size(10) * Anybase.new("012345678").size(10)).to eq(Anybase.new("012345678").size(20))
7
7
  end
8
8
 
9
9
  it "should normalize a number" do
10
- Anybase.new("01", :synonyms => {'0' => 'o', '1' => 'l'}, :ignore_case => true).normalize("l10oO1o").should == '1100010'
10
+ expect(Anybase.new("01", :synonyms => {'0' => 'o', '1' => 'l'}, :ignore_case => true).normalize("l10oO1o")).to eq('1100010')
11
11
  end
12
12
 
13
13
  it "raise if the sign is in the chars" do
14
- proc{ Anybase.new("01", :sign => '0') }.should raise_error
14
+ expect{ Anybase.new("01", :sign => '0') }.to raise_error(RuntimeError)
15
15
  end
16
16
 
17
17
  it "should allow matching" do
18
18
  funny_octal = Anybase.new("012345678", :synonyms => {'0' => 'oO'})
19
- funny_octal.match('235O').should == '235O'
20
- funny_octal.match('235Ozzz').should == '235O'
21
- funny_octal.match('a235O').should == nil
19
+ expect(funny_octal.match('235O')).to eq('235O')
20
+ expect(funny_octal.match('235Ozzz')).to eq('235O')
21
+ expect(funny_octal.match('a235O')).to eq(nil)
22
22
  end
23
- end
23
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anybase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
5
- prerelease:
4
+ version: 0.0.15
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joshual Hull
@@ -10,30 +9,36 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2011-12-20 00:00:00.000000000Z
12
+ date: 2016-02-11 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
- requirement: &70220794874880 !ruby/object:Gem::Requirement
18
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
- version_requirements: *70220794874880
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
26
28
  - !ruby/object:Gem::Dependency
27
29
  name: rake
28
- requirement: &70220794874400 !ruby/object:Gem::Requirement
29
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ! '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
- version_requirements: *70220794874400
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
37
42
  description: Numbers from anybase to anybase
38
43
  email:
39
44
  - joshbuddy@gmail.com
@@ -42,7 +47,8 @@ executables: []
42
47
  extensions: []
43
48
  extra_rdoc_files: []
44
49
  files:
45
- - .gitignore
50
+ - ".gitignore"
51
+ - ".travis.yml"
46
52
  - Gemfile
47
53
  - README.rdoc
48
54
  - Rakefile
@@ -56,33 +62,26 @@ files:
56
62
  - spec/util_spec.rb
57
63
  homepage: http://github.com/joshbuddy/anybase
58
64
  licenses: []
65
+ metadata: {}
59
66
  post_install_message:
60
67
  rdoc_options: []
61
68
  require_paths:
62
69
  - lib
63
70
  required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
71
  requirements:
66
- - - ! '>='
72
+ - - ">="
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
- segments:
70
- - 0
71
- hash: -1286050800804659122
72
75
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
76
  requirements:
75
- - - ! '>='
77
+ - - ">="
76
78
  - !ruby/object:Gem::Version
77
79
  version: '0'
78
- segments:
79
- - 0
80
- hash: -1286050800804659122
81
80
  requirements: []
82
81
  rubyforge_project: anybase
83
- rubygems_version: 1.8.10
82
+ rubygems_version: 2.4.6
84
83
  signing_key:
85
- specification_version: 3
84
+ specification_version: 4
86
85
  summary: Numbers from anybase to anybase
87
86
  test_files:
88
87
  - spec/from_spec.rb