binary 1.2.1 → 1.3.0
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/Gemfile.lock +1 -1
- data/README.md +18 -1
- data/binary.gemspec +3 -3
- data/lib/binary.rb +5 -3
- data/lib/binary/extensions.rb +4 -0
- data/lib/binary/extensions/array.rb +9 -0
- data/lib/binary/extensions/integer.rb +6 -0
- data/lib/binary/extensions/string.rb +6 -0
- data/lib/binary/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 655c7349b0f48a1172a4ff56001ffacdb35ea96fa679524cc2a3ccf87cc095f1
|
4
|
+
data.tar.gz: 641c38cc2c323d4ac026c51f2b8ba2e17df737deed9d2747e8ced0adf3188fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c9e16648b2f0e3aa53ff598f58e41d08c3d6fd00d8993fe4a3b8119983e7278ed3ea7e642d1af76cee801a348fe7062679ec44700d017fcefbe53335712345
|
7
|
+
data.tar.gz: 33f9370e77174484d52fdfe55233d6283a1cd18f145c3c5baf98bbf22aff780a606c29ee48f83562e7efc70b0fc4c253b013b44f8f14dec5c0076a106d2f2a45
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -29,27 +29,44 @@ Then to get the binary representation of a number, you just need to call `Binary
|
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
Binary.binary 2018
|
32
|
+
|
33
|
+
Or
|
34
|
+
|
35
|
+
2018.to_b
|
32
36
|
```
|
33
37
|
`Output: "11111100010"`.
|
34
38
|
|
35
39
|
Also you can pass an array of integers to the method to get an array of their binary values.
|
36
40
|
```ruby
|
37
41
|
Binary.binary([[7,9,11])
|
42
|
+
|
43
|
+
Or
|
44
|
+
|
45
|
+
[7,9,11].to_b
|
38
46
|
```
|
39
47
|
`Output: ["111", "1001", "1011"]`.
|
40
48
|
|
41
49
|
You can also convert binaries into integers by calling method `number` as follows:
|
42
50
|
```ruby
|
43
51
|
Binary.number "11111100010"
|
52
|
+
|
53
|
+
Or
|
54
|
+
|
55
|
+
"11111100010".to_num
|
44
56
|
```
|
45
57
|
`Output: 2018`.
|
46
58
|
|
47
59
|
```ruby
|
48
60
|
Binary.number(["111", "1001", "1011"])
|
61
|
+
|
62
|
+
Or
|
63
|
+
|
64
|
+
["111", "1001", "1011"].to_num
|
65
|
+
|
49
66
|
```
|
50
67
|
`Output: [7,9,11]`.
|
51
68
|
|
52
|
-
Other methods
|
69
|
+
Other methods available:
|
53
70
|
|
54
71
|
```ruby
|
55
72
|
# number of bits in a number's binary
|
data/binary.gemspec
CHANGED
@@ -7,11 +7,11 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "binary"
|
8
8
|
spec.version = Binary::VERSION
|
9
9
|
spec.authors = ["Mo Almishkawi"]
|
10
|
-
spec.email = ["mo@
|
10
|
+
spec.email = ["mo.almishkawi@gmail.com"]
|
11
11
|
spec.required_ruby_version = '~> 2.0'
|
12
12
|
|
13
|
-
spec.summary = "Convert
|
14
|
-
spec.description = "
|
13
|
+
spec.summary = "Convert numbers into binaries and binaries into numbers"
|
14
|
+
spec.description = "Convert numbers into binaries and binaries into numbers"
|
15
15
|
spec.homepage = ""
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
data/lib/binary.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
require_relative 'binary/extensions.rb'
|
3
|
+
require 'binary/version'
|
4
|
+
require 'prime'
|
3
5
|
|
4
6
|
module Binary
|
5
7
|
def self.binary(input=nil)
|
@@ -53,6 +55,6 @@ module Binary
|
|
53
55
|
def self.method_missing(method, *args, &block)
|
54
56
|
puts "There's no method #{method} found in Binary module."
|
55
57
|
puts 'Methods available are:'
|
56
|
-
puts (Binary.methods - Object.methods)
|
58
|
+
puts (Binary.methods - Object.methods - [:method_missing])
|
57
59
|
end
|
58
60
|
end
|
data/lib/binary/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mo Almishkawi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,10 +52,9 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
56
|
-
and some other methods
|
55
|
+
description: Convert numbers into binaries and binaries into numbers
|
57
56
|
email:
|
58
|
-
- mo@
|
57
|
+
- mo.almishkawi@gmail.com
|
59
58
|
executables: []
|
60
59
|
extensions: []
|
61
60
|
extra_rdoc_files: []
|
@@ -72,6 +71,10 @@ files:
|
|
72
71
|
- bin/setup
|
73
72
|
- binary.gemspec
|
74
73
|
- lib/binary.rb
|
74
|
+
- lib/binary/extensions.rb
|
75
|
+
- lib/binary/extensions/array.rb
|
76
|
+
- lib/binary/extensions/integer.rb
|
77
|
+
- lib/binary/extensions/string.rb
|
75
78
|
- lib/binary/version.rb
|
76
79
|
homepage: ''
|
77
80
|
licenses:
|
@@ -96,5 +99,5 @@ rubyforge_project:
|
|
96
99
|
rubygems_version: 2.7.4
|
97
100
|
signing_key:
|
98
101
|
specification_version: 4
|
99
|
-
summary: Convert
|
102
|
+
summary: Convert numbers into binaries and binaries into numbers
|
100
103
|
test_files: []
|