rya 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0598dd96f2bf67601ec24f16e84d13f7e5f8c1c
4
- data.tar.gz: 57cf0d5cdf6033ceae57e9639784a166d0d9257f
3
+ metadata.gz: 17faa5426332cbf2e4feef95b01dce87da18cbd5
4
+ data.tar.gz: c3443b989de0b26626635c564a4f226fd2d3cf03
5
5
  SHA512:
6
- metadata.gz: d9fd3046fdbc13045f55959d002634eabbe21c551237709a0af24e9668a82d776e55a42356b9606845ddf30f59ae3ac8fd9983861a6f2acafdedfae82eb9e34e
7
- data.tar.gz: a0b899888438ae57a78b170be5bd545c6924f6a8db903c4f5eba3be86e5b4d5967aeab443807e1e8a23c7a036b16fa51750db27a80c87b79471d7d9c01db7a2a
6
+ metadata.gz: af2e443c83eff05d51c31acd6609145ac37b1c07bc13357fcc817262cbc7c5893bd55395a8a4db04e83df81711feaf450fddd92b85cfdd3f4c5bb53ce9a78f79
7
+ data.tar.gz: 9dea5ef86e1cc1f577aebe6010792580c29d258388ea714992f4cdd1302a7d5fdf7c7c76a48187b3dcc650b9dacfc5d29a70c629fc3f4914db7820c95aa88b4c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rya (0.3.0)
4
+ rya (0.4.0)
5
5
  abort_if (~> 0.2.0)
6
6
  systemu (~> 2.6, >= 2.6.5)
7
7
 
@@ -32,6 +32,50 @@ module Rya
32
32
  end
33
33
  end
34
34
 
35
+ module String
36
+
37
+ # Use dynamic programming to find the length of the longest common substring.
38
+ #
39
+ # @param other The other string to test against.
40
+ #
41
+ # @example
42
+ # str = String.new("apple").extend Rya::CoreExtensions::String
43
+ # other = "ppie"
44
+ #
45
+ # str.longest_common_substring other #=> 2
46
+ #
47
+ # @note This is the algorithm from https://www.geeksforgeeks.org/longest-common-substring/
48
+ def longest_common_substring other
49
+ if self.empty? || other.empty?
50
+ return 0
51
+ end
52
+
53
+ self_len = self.length
54
+ other_len = other.length
55
+
56
+ longest_common_suffix = Object::Array.new(self_len + 1) { Object::Array.new(other_len + 1, 0) }
57
+
58
+ len = 0
59
+
60
+ (self_len + 1).times do |i|
61
+ (other_len + 1).times do |j|
62
+ if i.zero? || j.zero? # this is for the dummy column
63
+ longest_common_suffix[i][j] = 0
64
+ elsif self[i - 1] == other[j - 1]
65
+ val = longest_common_suffix[i - 1][j - 1] + 1
66
+ longest_common_suffix[i][j] = val
67
+
68
+ len = [len, val].max
69
+ else
70
+ longest_common_suffix[i][j] = 0
71
+ end
72
+ end
73
+ end
74
+
75
+ len
76
+ end
77
+ end
78
+
35
79
  module Time
36
80
  # Nicely format date and time
37
81
  def date_and_time fmt = "%F %T.%L"
@@ -114,13 +158,15 @@ module Rya
114
158
  end
115
159
  end
116
160
  end
161
+
117
162
  end
118
163
  end
119
164
 
120
165
  module Rya
121
- # Mainly for external use within the CoreExtensions module definitions
166
+ # Mainly for use within the CoreExtensions module definitions
122
167
  module ExtendedClasses
123
- MATH = Class.new.extend(Rya::CoreExtensions::Math)
168
+ MATH = Class.new.extend(Rya::CoreExtensions::Math)
169
+ STRING = Class.new.extend(Rya::CoreExtensions::String)
124
170
  end
125
171
  end
126
172
 
@@ -1,3 +1,3 @@
1
1
  module Rya
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Moore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-29 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler