hexable 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/hexable.gemspec +3 -2
- data/lib/hexable.rb +65 -9
- data/lib/hexable/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83a406d79077051def30b079ca8640ce7a2c62e9
|
4
|
+
data.tar.gz: 039a30914928860aa6cbf298ee0a75325e4b8c61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 994f6678ed505296cd93279187598f3b2a0c75ff8dcdf6bed327b9cea53d98a558809ac101c7cc166a4491309c7408094f888a47cbf1745eb7192975e5525b7a
|
7
|
+
data.tar.gz: c3b736ac0d93b9bfeb5d97b41d6b41df465ccfca90de343c5bc887ff63464f5b47fadbc2d289fd0c5feea8f4d07a7d21d410eadf36254c900db4baf4583e2ca2
|
data/README.md
CHANGED
data/hexable.gemspec
CHANGED
@@ -15,12 +15,13 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
17
|
# delete this section to allow pushing this gem to any host.
|
18
|
+
=begin
|
18
19
|
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org/"
|
20
21
|
else
|
21
22
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
23
|
end
|
23
|
-
|
24
|
+
=end
|
24
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
26
|
spec.bindir = "exe"
|
26
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/hexable.rb
CHANGED
@@ -3,48 +3,104 @@ require "hexable/version"
|
|
3
3
|
module Hexable
|
4
4
|
class Number
|
5
5
|
def initialize(num)
|
6
|
-
@number = (
|
6
|
+
@number = num.eql?(nil) ? num : 0
|
7
|
+
@base = 10
|
7
8
|
end
|
8
9
|
|
9
10
|
def number(num)
|
10
11
|
@number = num
|
11
12
|
end
|
12
13
|
|
14
|
+
def base
|
15
|
+
return @base
|
16
|
+
end
|
17
|
+
|
13
18
|
def binary
|
19
|
+
@base = 2
|
14
20
|
return @number.to_i().to_s(2)
|
15
21
|
end
|
16
22
|
|
17
23
|
def octal
|
24
|
+
@base = 8
|
18
25
|
return @number.to_i().to_s(8)
|
19
26
|
end
|
20
27
|
|
21
28
|
def decimal
|
29
|
+
@base = 10
|
22
30
|
return Integer(@number)
|
23
31
|
end
|
24
32
|
|
25
33
|
def hex
|
34
|
+
@base = 16
|
26
35
|
return @number.to_i().to_s(16)
|
27
36
|
end
|
28
|
-
=begin
|
29
|
-
def base64
|
30
37
|
|
38
|
+
def base32
|
39
|
+
@base = 32
|
40
|
+
return @number.to_i().to_s(32)
|
31
41
|
end
|
32
42
|
|
33
|
-
def add()
|
43
|
+
def add(x)
|
44
|
+
num = decimal(x)
|
45
|
+
num += @number
|
46
|
+
return convert(num)
|
47
|
+
end
|
34
48
|
|
49
|
+
def subtract(x)
|
50
|
+
num = decimal(x)
|
51
|
+
num -= @number
|
52
|
+
return convert(num)
|
35
53
|
end
|
36
54
|
|
37
|
-
def
|
55
|
+
def multiply(x)
|
56
|
+
num = decimal(x)
|
57
|
+
num *= @number
|
58
|
+
return convert(num)
|
59
|
+
end
|
38
60
|
|
61
|
+
def divide(x)
|
62
|
+
num = decimal(x)
|
63
|
+
num /= @number
|
64
|
+
return convert(num)
|
39
65
|
end
|
40
66
|
|
41
|
-
|
67
|
+
private
|
42
68
|
|
69
|
+
def convert(num)
|
70
|
+
case @base
|
71
|
+
when 2
|
72
|
+
return binary(num)
|
73
|
+
when 8
|
74
|
+
return octal(num)
|
75
|
+
when 10
|
76
|
+
return decimal(num)
|
77
|
+
when 16
|
78
|
+
return hex(num)
|
79
|
+
when 32
|
80
|
+
return base32(num)
|
81
|
+
end
|
43
82
|
end
|
44
83
|
|
45
|
-
|
84
|
+
end
|
46
85
|
|
47
|
-
|
48
|
-
=
|
86
|
+
def add(x,y)
|
87
|
+
a = Hexable::Number.new(x)
|
88
|
+
return a.add(y)
|
49
89
|
end
|
90
|
+
|
91
|
+
def subtract(x,y)
|
92
|
+
a = Hexable::Number.new(x)
|
93
|
+
return a.subtract(y)
|
94
|
+
end
|
95
|
+
|
96
|
+
def multiply(x,y)
|
97
|
+
a = Hexable::Number.new(x)
|
98
|
+
return a.multiply(y)
|
99
|
+
end
|
100
|
+
|
101
|
+
def divide(x,y)
|
102
|
+
a = Hexable::Number.new(x)
|
103
|
+
return a.divide(y)
|
104
|
+
end
|
105
|
+
|
50
106
|
end
|
data/lib/hexable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- austin.vecchio
|
@@ -58,8 +58,7 @@ files:
|
|
58
58
|
- lib/hexable/version.rb
|
59
59
|
homepage: https://github.com/avecchio/hexable
|
60
60
|
licenses: []
|
61
|
-
metadata:
|
62
|
-
allowed_push_host: https://rubygems.org
|
61
|
+
metadata: {}
|
63
62
|
post_install_message:
|
64
63
|
rdoc_options: []
|
65
64
|
require_paths:
|