basecustom 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/basecustom/version.rb +5 -1
- data/lib/basecustom.rb +11 -8
- data/test/{test_bc.rb → bc_test.rb} +11 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2233eb5a114e59208ab286a6538e4cbbf7fe49b
|
4
|
+
data.tar.gz: a001b263d87d549297dea8fb39617dfde233586a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a34d824e497bfc29dc5f1aa77b610933a9bb775003dee7edde96e95f33313d6088d42f152e3f5d5a5579f1ba41fe66c90d12f3ca55c4233d0182413cd5da5ba2
|
7
|
+
data.tar.gz: 4b2901922a0b9629fdd89ff9ce7ab76904c45d38f719e433682f0b3002578ad6d385a71216a413776e46b1e82b7d704480677df90d0530aa4046568965072705
|
data/README.md
CHANGED
@@ -32,6 +32,11 @@ baseABC.base(123)
|
|
32
32
|
|
33
33
|
# Version History
|
34
34
|
|
35
|
+
Version 1.0.1
|
36
|
+
* Enabled use of special characters like newline (\n) or tab (\t) to be counted
|
37
|
+
as acceptable numeric characters. These characters can now also be printed with
|
38
|
+
expected behavior.
|
39
|
+
|
35
40
|
Version 1.0.0
|
36
41
|
* Bump version number. Gem has proven ready as a version 1 release.
|
37
42
|
|
data/lib/basecustom/version.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
class BaseCustom
|
2
|
-
VERSION = "1.0.
|
2
|
+
VERSION = "1.0.1"
|
3
3
|
end
|
4
4
|
|
5
|
+
# Version 1.0.1
|
6
|
+
# * Enabled use of special characters like newline (\n) or tab (\t) to be counted
|
7
|
+
# as acceptable numeric characters. These characters can now also be printed with
|
8
|
+
# expected behavior.
|
5
9
|
# Version 1.0.0
|
6
10
|
# * Bump version number. Gem has proven ready as a version 1 release.
|
7
11
|
# Version 0.1.8
|
data/lib/basecustom.rb
CHANGED
@@ -7,9 +7,9 @@ require 'basecustom/version'
|
|
7
7
|
|
8
8
|
class BaseCustom
|
9
9
|
|
10
|
-
def initialize(array_in, delim =
|
10
|
+
def initialize(array_in, delim = "")
|
11
11
|
if array_in.is_a?(String)
|
12
|
-
array_in = array_in.split(delim)
|
12
|
+
array_in = array_in.split(/#{delim}/)
|
13
13
|
end
|
14
14
|
if not array_in.is_a?(Array)
|
15
15
|
raise "Invalid type! Please provide a String or an Array."
|
@@ -18,10 +18,13 @@ class BaseCustom
|
|
18
18
|
if array_in.any? { |i| not i.is_a?(String) }
|
19
19
|
raise "Invalid type! Each array element must be a String."
|
20
20
|
end
|
21
|
+
if !delim.is_a? String
|
22
|
+
raise "Invalid delimiter type! Delimiter value must be a String."
|
23
|
+
end
|
21
24
|
if array_in.any? { |i| i.length > 1 }
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
if delim.empty?
|
26
|
+
raise "Error! You must define a delimiter when using multiple characters for a base."
|
27
|
+
end
|
25
28
|
end
|
26
29
|
@BASE_PRIMITIVES_ARRAY = array_in.uniq
|
27
30
|
@BASE_PRIMITIVES_HASH = Hash[@BASE_PRIMITIVES_ARRAY.each_with_index.map {|x,idx| [x, idx]}]
|
@@ -30,11 +33,11 @@ class BaseCustom
|
|
30
33
|
|
31
34
|
def base(input_val)
|
32
35
|
if input_val.is_a?(String)
|
33
|
-
if input_val.split(@delim).any? { |i| not @BASE_PRIMITIVES_ARRAY.include?(i) }
|
36
|
+
if input_val.split(/#{@delim}/).any? { |i| not @BASE_PRIMITIVES_ARRAY.include?(i) }
|
34
37
|
raise "Characters used are not in predefined base!"
|
35
38
|
end
|
36
39
|
i, i_out = 0, 0
|
37
|
-
input_val.split(@delim).reverse.each do |c|
|
40
|
+
input_val.split(/#{@delim}/).reverse.each do |c|
|
38
41
|
place = @BASE_PRIMITIVES_HASH.size ** i
|
39
42
|
i_out += @BASE_PRIMITIVES_HASH[c] * place
|
40
43
|
i += 1
|
@@ -44,7 +47,7 @@ class BaseCustom
|
|
44
47
|
elsif input_val.is_a?(Integer)
|
45
48
|
return @BASE_PRIMITIVES_HASH.first[0] if input_val == 0
|
46
49
|
number = input_val
|
47
|
-
result =
|
50
|
+
result = ""
|
48
51
|
while(number != 0)
|
49
52
|
result = @BASE_PRIMITIVES_ARRAY[number % @BASE_PRIMITIVES_ARRAY.size ].to_s + @delim + result
|
50
53
|
number = Integer(number/@BASE_PRIMITIVES_ARRAY.size)
|
@@ -30,9 +30,10 @@ class TestBaseCustom < Test::Unit::TestCase
|
|
30
30
|
assert_raise RuntimeError, LoadError do base2.base(:nonexistant); end
|
31
31
|
assert_raise RuntimeError, LoadError do base2.base('abc'); end
|
32
32
|
assert_raise RuntimeError, LoadError do base2.base(4.5); end
|
33
|
-
assert_raise RuntimeError, LoadError do
|
34
|
-
assert_raise RuntimeError, LoadError do
|
35
|
-
assert_raise RuntimeError, LoadError do
|
33
|
+
assert_raise RuntimeError, LoadError do BaseCustom.new(%w[:a :b :c]); end
|
34
|
+
assert_raise RuntimeError, LoadError do BaseCustom.new(0..9); end
|
35
|
+
assert_raise RuntimeError, LoadError do BaseCustom.new(['0','1',2]); end
|
36
|
+
assert_raise RuntimeError, LoadError do BaseCustom.new("123", //); end
|
36
37
|
end
|
37
38
|
|
38
39
|
def test_delim
|
@@ -58,4 +59,11 @@ class TestBaseCustom < Test::Unit::TestCase
|
|
58
59
|
assert baseMND.base(12) == "bb:bb:aa:"
|
59
60
|
assert baseMND.base("bb:bb:aa:") == 12
|
60
61
|
end
|
62
|
+
|
63
|
+
def test_special_characters
|
64
|
+
baseSC = BaseCustom.new("\n 0 1 \t", " ")
|
65
|
+
assert baseSC.base(12345) == "\t \n \n \n \t 1 0 "
|
66
|
+
baseSC = BaseCustom.new(["\n", "0", "1", "\t"])
|
67
|
+
assert baseSC.base(12345) == "\t\n\n\n\t10"
|
68
|
+
end
|
61
69
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basecustom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark / 6ftDan(TM)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Define your own numberic base! Highly advanced and ultimately simple!
|
14
|
-
email:
|
14
|
+
email: 6ftdan@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
@@ -20,7 +20,7 @@ files:
|
|
20
20
|
- README.md
|
21
21
|
- lib/basecustom.rb
|
22
22
|
- lib/basecustom/version.rb
|
23
|
-
- test/
|
23
|
+
- test/bc_test.rb
|
24
24
|
homepage: https://rubygems.org/gems/basecustom
|
25
25
|
licenses:
|
26
26
|
- The MIT License (MIT)
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.
|
44
|
+
rubygems_version: 2.4.5
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: Define your own numberic base!
|