andys_convenience_methods 0.0.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 +7 -0
- data/lib/andy_convenience.rb +66 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5522693b56e6355cd5a25f944484233542cfda5b
|
4
|
+
data.tar.gz: 321b1b5dd51d22d6844ac2e5e8701bc87bb2a10f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e98a152a7e0f4b655feb55f2504ef3e34d080806c0ffab1c8489b90faa7200eeb5fb04ed8d55a0d71e244111f0fabcb832263bc55274745366177be8658002b
|
7
|
+
data.tar.gz: 609c8b2208b1f6f734e4ab61923ca53f5a68c72db3af5a9f4ce2adbae15f4b32acb648adcca7d289354578ae0ec46234bfe75b6f3e7c60b1d7b43858dfe87ab8
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class String
|
2
|
+
def to_binary
|
3
|
+
ascii = []
|
4
|
+
self.each_byte {|char| ascii << char}
|
5
|
+
ascii.map{ |n| n.to_binary }.join(' ')
|
6
|
+
end
|
7
|
+
|
8
|
+
def crunch(str)
|
9
|
+
str.chars.chunk{|s| s}.map(&:first).join
|
10
|
+
end
|
11
|
+
|
12
|
+
def -(n)
|
13
|
+
str = self
|
14
|
+
n.times { str = str.chop }
|
15
|
+
str
|
16
|
+
end
|
17
|
+
|
18
|
+
def /(n)
|
19
|
+
left = self.size % n
|
20
|
+
reg = Regexp.new(".{#{n}}")
|
21
|
+
res = self.scan(reg)
|
22
|
+
res += [self[(0 - left)..-1]]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Integer
|
27
|
+
def increment(interval = 1, operator = :+, seq = 1)
|
28
|
+
int = self
|
29
|
+
seq.times { int = int.send(operator.to_sym, interval) }
|
30
|
+
int
|
31
|
+
end
|
32
|
+
|
33
|
+
def stringcrement(interval = 1, operator = :+, seq = 1)
|
34
|
+
self.increment(interval, operator, seq).to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_binary
|
38
|
+
final_string = ''
|
39
|
+
bins = binlib.select { |n| n <= self }.reverse
|
40
|
+
return '0' if bins.empty?
|
41
|
+
return '1' if bins[0] == 1
|
42
|
+
final_string << '1'
|
43
|
+
difference = self - bins[0]
|
44
|
+
bins[1..-1].each do |bin|
|
45
|
+
if difference >= bin
|
46
|
+
final_string << '1'
|
47
|
+
difference -= bin
|
48
|
+
else
|
49
|
+
final_string << '0'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
final_string
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def binlib
|
58
|
+
counter = 0
|
59
|
+
library = []
|
60
|
+
until counter == 1000
|
61
|
+
library << (2 ** counter)
|
62
|
+
counter += 1
|
63
|
+
end
|
64
|
+
library
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andys_convenience_methods
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Rosenberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A few convenience methods
|
14
|
+
email: andynaterosenberg@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/andy_convenience.rb
|
20
|
+
homepage: https://github.com/AndyRosenberg/andy_conv
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.6.11
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Library addons
|
43
|
+
test_files: []
|