string-machete 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/string-machete.rb +39 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8de4ab6e94c90e1179ad77bf682e18df8a0f3260
4
+ data.tar.gz: e612b4d947d2b7064c2496159f3bbed8ea09a4a5
5
+ SHA512:
6
+ metadata.gz: c40927e516c5a8cce46dcd3ef4595040b519b0543a55fef6afee80bd33dc50d5f343a83d0da9c96c4b32f71dad58e4c5207c88858f53c3de76ad0721d67f1e54
7
+ data.tar.gz: 9bfa97a50911411679e09c46527af59854c32ddc68bc97e2fa841c66d6b2cbb6d491c11a1b872a5375b10b418a30ea5c848e6d7b676c0ed892635db56f90e092
@@ -0,0 +1,39 @@
1
+ module StringMachete
2
+ [:halves, :thirds, :fourths, :fifths, :sixths,
3
+ :sevenths, :eigths, :nineths, :tenths].each_with_index do |m_name, index|
4
+ define_method(m_name) do
5
+ return nil if self.length % (index+2) > 0
6
+
7
+ interval = self.length / (index+2)
8
+ e_interval = self.length % (index+2)
9
+ intervals = Array.new(index+2) { |i| [i*interval, (i+1)*interval] }
10
+
11
+ intervals.map do |i|
12
+ self[i[0]...i[1]]
13
+ end
14
+ end
15
+ end
16
+
17
+ def /(divisor)
18
+ interval = self.length / divisor
19
+ e_interval = self.length % divisor
20
+ intervals = Array.new(divisor) { |i| [i*interval, (i+1)*interval] }
21
+
22
+ intervals.map do |i|
23
+ self[i[0]...i[1]]
24
+ end
25
+ end
26
+
27
+ def %(divisor)
28
+ e_interval = self.length % divisor
29
+
30
+ e_interval > 0 ? [self[-e_interval..-1]] : []
31
+ end
32
+
33
+ def divide_by divisor
34
+ remainder = self % divisor
35
+ (self / divisor) + (remainder.any? ? [remainder] : [])
36
+ end
37
+ end
38
+
39
+ String.include StringMachete
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string-machete
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Brandt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Makes strings divisible!
14
+ email: cbrandt92@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/string-machete.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Makes strings divisible!
44
+ test_files: []