hexable 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hexable.gemspec +1 -9
- data/lib/hexable.rb +52 -13
- data/lib/hexable/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12c2a85a8366022e3168fe32e159be78ffc04806
|
4
|
+
data.tar.gz: 0e69ac5c2c2cd776e1d3aa81465f7277b5aef3fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8cd38fca54bd2eb87c950d9d4c6a587031086423175e9cd051f82edceda08418ca30b29b73839aa2f2f86e853811416feb5c7112f9529c0a7d646efe79ac14
|
7
|
+
data.tar.gz: 6a9304f26510a5d635641b76eb84da1e158ab06cf459c9ca43c477554d8995ba04b8bef62fbccf75c922219d741d3113723792a35ca2590f914c12552a73aa49
|
data/hexable.gemspec
CHANGED
@@ -13,15 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = %q{Convert between binary octal decimal hex and base64 with add subtract multiply and divide operations}
|
14
14
|
spec.homepage = "https://github.com/avecchio/hexable"
|
15
15
|
|
16
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
-
# delete this section to allow pushing this gem to any host.
|
18
|
-
=begin
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org/"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
end
|
24
|
-
=end
|
25
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
17
|
spec.bindir = "exe"
|
27
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -29,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
29
20
|
|
30
21
|
spec.add_development_dependency "bundler", "~> 1.11"
|
31
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
32
24
|
end
|
data/lib/hexable.rb
CHANGED
@@ -2,9 +2,11 @@ require "hexable/version"
|
|
2
2
|
|
3
3
|
module Hexable
|
4
4
|
class Number
|
5
|
-
def initialize(num)
|
6
|
-
@number = num.eql?(nil) ? num : 0
|
7
|
-
@base = 10
|
5
|
+
def initialize(num, base, mode)
|
6
|
+
@number = num.eql?(nil) ? num.to_i(base) : 0
|
7
|
+
@base = base.eql?(nil) ? base : 10
|
8
|
+
# default dynamic is off, so static is false
|
9
|
+
@mode = mode.eql?(nil) ? mode : false
|
8
10
|
end
|
9
11
|
|
10
12
|
def number(num)
|
@@ -16,28 +18,63 @@ module Hexable
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def binary
|
19
|
-
|
20
|
-
|
21
|
+
transform = @number.to_i().to_s(2)
|
22
|
+
if @mode
|
23
|
+
@base = 2
|
24
|
+
@number = transform
|
25
|
+
else
|
26
|
+
return transform
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
def octal
|
24
|
-
|
25
|
-
|
31
|
+
transform = @number.to_i().to_s(8)
|
32
|
+
if @mode
|
33
|
+
@base = 8
|
34
|
+
@number = transform
|
35
|
+
else
|
36
|
+
return transform
|
37
|
+
end
|
26
38
|
end
|
27
39
|
|
28
40
|
def decimal
|
29
|
-
|
30
|
-
|
41
|
+
transform = Integer(@number)
|
42
|
+
if @mode
|
43
|
+
@base = 10
|
44
|
+
@number = transform
|
45
|
+
else
|
46
|
+
return transform
|
47
|
+
end
|
31
48
|
end
|
32
49
|
|
33
50
|
def hex
|
34
|
-
|
35
|
-
|
51
|
+
transform = @number.to_i().to_s(16)
|
52
|
+
if @mode
|
53
|
+
@base = 16
|
54
|
+
@number = transform
|
55
|
+
else
|
56
|
+
return transform
|
57
|
+
end
|
36
58
|
end
|
37
59
|
|
38
60
|
def base32
|
39
|
-
|
40
|
-
|
61
|
+
transform = @number.to_i().to_s(32)
|
62
|
+
if @mode
|
63
|
+
@base = 32
|
64
|
+
@number = transform
|
65
|
+
else
|
66
|
+
return transform
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def base64
|
71
|
+
transform = 4#@number.to_i().to_s(32)
|
72
|
+
if @mode
|
73
|
+
@base = 64
|
74
|
+
@number = transform
|
75
|
+
else
|
76
|
+
return transform
|
77
|
+
end
|
41
78
|
end
|
42
79
|
|
43
80
|
def add(x)
|
@@ -79,6 +116,8 @@ module Hexable
|
|
79
116
|
return n.hex
|
80
117
|
when 32
|
81
118
|
return n.base32
|
119
|
+
when 64
|
120
|
+
return n.base64
|
82
121
|
end
|
83
122
|
end
|
84
123
|
|
data/lib/hexable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- austin.vecchio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
41
55
|
description: Convert between binary octal decimal hex and base64 with add subtract
|
42
56
|
multiply and divide operations
|
43
57
|
email:
|