rya 0.3.0 → 0.4.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rya/core_extensions.rb +48 -2
- data/lib/rya/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17faa5426332cbf2e4feef95b01dce87da18cbd5
|
4
|
+
data.tar.gz: c3443b989de0b26626635c564a4f226fd2d3cf03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af2e443c83eff05d51c31acd6609145ac37b1c07bc13357fcc817262cbc7c5893bd55395a8a4db04e83df81711feaf450fddd92b85cfdd3f4c5bb53ce9a78f79
|
7
|
+
data.tar.gz: 9dea5ef86e1cc1f577aebe6010792580c29d258388ea714992f4cdd1302a7d5fdf7c7c76a48187b3dcc650b9dacfc5d29a70c629fc3f4914db7820c95aa88b4c
|
data/Gemfile.lock
CHANGED
data/lib/rya/core_extensions.rb
CHANGED
@@ -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
|
166
|
+
# Mainly for use within the CoreExtensions module definitions
|
122
167
|
module ExtendedClasses
|
123
|
-
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
|
|
data/lib/rya/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|