binary 1.0.1 → 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/binary.rb +30 -3
  3. data/lib/binary/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbd78632136fb758014344e3b6155eb7bfc706f0f5b014748370784f49d82845
4
- data.tar.gz: 52a8c5384269d925611dbf7b8c8876308c0de241ceac54006e17f9a486d29d53
3
+ metadata.gz: ec27b3cd7dfa1d2bfcf834091ba8ccdc1122242f0599460903079baee8f40a36
4
+ data.tar.gz: 769b49ac606231ff06b07eb8e1e614d8188acdea81e0ffa0c08d80dce5492e14
5
5
  SHA512:
6
- metadata.gz: d9f87c42a7289da21d750ecdc8522162c148ea1ed1e160b12536b3bc89ea07d20ca6e7df421e8dde9348929ce03ed641d275ecae9ec52cf250d71a2d2b2aaae3
7
- data.tar.gz: 1ea3653879ced8485a53e980fa382309bebd5c2b69e2993f814577522c372e55b94c0518bf51733edf7ecc52f495b9150fa9a185bc4d8ee546a11831ca5c4bc4
6
+ metadata.gz: 4bda31ed4f9c3e5f737bc44d4ae688c92fec03020c7bd03e08cff05bfca8401c9419ffe13ad4f3294178f4b6f95bf533fef882e3353bc54e66cef0975bccc105
7
+ data.tar.gz: 2775541257d014f3b0347dc14f9d093e1065679ad40661daa4aa923229124dedb7a3b40d74c7b505dd3176a6d70dd274d8525ecce35ae6df78f40da0d23cc0c1
@@ -1,11 +1,38 @@
1
1
  require "binary/version"
2
+ require "prime"
2
3
 
3
4
  module Binary
4
- def self.binary(input=nil)
5
- if input.class == Array
6
- input.map { |num| num.class == Integer ? num.to_s(2) : nil }
5
+ def self.binary(input=nil)
6
+ if input.class == Array
7
+ input.map { |num| num.class == Integer ? num.to_s(2) : nil }
7
8
  elsif input.class == Integer
9
+ input = input.abs if input < 0
8
10
  input.to_s(2)
11
+ else
12
+ nil
9
13
  end
10
14
  end
15
+
16
+ def self.bits num
17
+ binary = binary(num) if num
18
+ binary.length
19
+ end
20
+
21
+ def self.zeros num
22
+ binary = binary(num) if num
23
+ binary.count("0")
24
+ end
25
+
26
+ def self.ones num
27
+ binary = binary(num) if num
28
+ binary.count("1")
29
+ end
30
+
31
+ def self.prime num
32
+ binaries = []
33
+ Prime.each(num) do |prime|
34
+ binaries << binary(prime)
35
+ end
36
+ binaries
37
+ end
11
38
  end
@@ -1,3 +1,3 @@
1
1
  module Binary
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.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.0.1
4
+ version: 1.1.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-03-06 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler