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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aa42f93d269656e319c5d5325bd0e006b9ae2ce45e070a68e7faf8056c413b7
4
- data.tar.gz: 426cfdb85b17a902e6567ff9d5f0f659061376c24d03533dce5d8ce195efd0a6
3
+ metadata.gz: 655c7349b0f48a1172a4ff56001ffacdb35ea96fa679524cc2a3ccf87cc095f1
4
+ data.tar.gz: 641c38cc2c323d4ac026c51f2b8ba2e17df737deed9d2747e8ced0adf3188fc8
5
5
  SHA512:
6
- metadata.gz: 6c1944974fd21d2bfd27c4b93aad4dbcca58c24ea2c6a53b2a5419d8ae326bd16ecc9c7abf9dbe960b308c5e9950369236c628c2bf5355ee48ff20ee64f2559a
7
- data.tar.gz: e44408c1700cffc09af38302444cde7840a99be02964b6c987e854c2c74d728797d7a9fa2829dd4a1354ccbcf4921a55e491a5e3e4a8d357591f6713d295e4a6
6
+ metadata.gz: d5c9e16648b2f0e3aa53ff598f58e41d08c3d6fd00d8993fe4a3b8119983e7278ed3ea7e642d1af76cee801a348fe7062679ec44700d017fcefbe53335712345
7
+ data.tar.gz: 33f9370e77174484d52fdfe55233d6283a1cd18f145c3c5baf98bbf22aff780a606c29ee48f83562e7efc70b0fc4c253b013b44f8f14dec5c0076a106d2f2a45
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binary (1.1.1)
4
+ binary (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 you can use:
69
+ Other methods available:
53
70
 
54
71
  ```ruby
55
72
  # number of bits in a number's binary
@@ -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@almishkawi.me"]
10
+ spec.email = ["mo.almishkawi@gmail.com"]
11
11
  spec.required_ruby_version = '~> 2.0'
12
12
 
13
- spec.summary = "Convert a number into a binary or convert a binary into a number"
14
- spec.description = "Takes integers and returns binaries or takes binaries and returns numbers and some other methods"
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
 
@@ -1,5 +1,7 @@
1
- require "binary/version"
2
- require "prime"
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
@@ -0,0 +1,4 @@
1
+
2
+ require 'binary/extensions/array'
3
+ require 'binary/extensions/integer'
4
+ require 'binary/extensions/string'
@@ -0,0 +1,9 @@
1
+ class Array
2
+
3
+ def to_b
4
+ Binary.binary self
5
+ end
6
+ def to_num
7
+ Binary.number self
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class Integer
2
+
3
+ def to_b
4
+ Binary.binary self
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class String
2
+
3
+ def to_num
4
+ Binary.number self
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Binary
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
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.2.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-02 00:00:00.000000000 Z
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: Takes integers and returns binaries or takes binaries and returns numbers
56
- and some other methods
55
+ description: Convert numbers into binaries and binaries into numbers
57
56
  email:
58
- - mo@almishkawi.me
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 a number into a binary or convert a binary into a number
102
+ summary: Convert numbers into binaries and binaries into numbers
100
103
  test_files: []