epitools 0.5.112 → 0.5.113
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/autoloads.rb +1 -0
- data/lib/epitools/core_ext/object.rb +23 -21
- data/lib/epitools/core_ext/string.rb +35 -2
- data/spec/core_ext_spec.rb +21 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac614574fc21c61b88fb73f208d16c4960c5a3165a78844a56e26c8326e7bf82
|
4
|
+
data.tar.gz: 75914fb5972be2115ce1704c896f183300057ab6422be80f7dd50ab5088a152c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd211d087deebafc7fec99003e6dfd20293cac20b9ad7db36cbd03641b1c2b4a4ddb3f1609fd236895cb596444012f5829ee27b2562271d6ca71a1696daaa205
|
7
|
+
data.tar.gz: 3c5c750c2767cfc600ae78538ea6339859e8a7c50d4b4b8876efebbbbb658d8a56166e29d50f8a72e72ac12c7e7a7a64a2d179c189f1b3901bc8e26fa4370a09
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.113
|
data/lib/epitools/autoloads.rb
CHANGED
@@ -74,27 +74,6 @@ class Object
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
#
|
78
|
-
# Cache (memoize) the result of an instance method the first time
|
79
|
-
# it's called, storing this value in the "@methodname" instance variable,
|
80
|
-
# and always return this value on subsequent calls.
|
81
|
-
#
|
82
|
-
def self.memoize(*methods)
|
83
|
-
methods.each do |meth|
|
84
|
-
old_method = instance_method(meth)
|
85
|
-
|
86
|
-
if old_method.arity == 0
|
87
|
-
ivarname = "@#{meth}"
|
88
|
-
|
89
|
-
define_method meth do
|
90
|
-
instance_variable_get(ivarname) or instance_variable_set(ivarname, old_method.bind(self).call)
|
91
|
-
end
|
92
|
-
else
|
93
|
-
raise "Can't memoize methods with arguments. (YET.)"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
77
|
#
|
99
78
|
# Serialize this object to a binary String, using Marshal.dump.
|
100
79
|
#
|
@@ -231,3 +210,26 @@ class NotWrapper < BasicObject # :nodoc:
|
|
231
210
|
end
|
232
211
|
end
|
233
212
|
|
213
|
+
|
214
|
+
class Module
|
215
|
+
|
216
|
+
#
|
217
|
+
# Cache (memoize) the result of an instance method the first time
|
218
|
+
# it's called, storing this value in the "@__memoized_#{methodname}_cache"
|
219
|
+
# instance variable, and always return this value on subsequent calls
|
220
|
+
# (unless the returned value is nil).
|
221
|
+
#
|
222
|
+
def memoize(*methods)
|
223
|
+
# alias_method is faster than define_method + old.bind(self).call
|
224
|
+
methods.each do |meth|
|
225
|
+
alias_method "__memoized__#{meth}", meth
|
226
|
+
module_eval <<-EOF
|
227
|
+
def #{meth}(*a, &b)
|
228
|
+
# assumes the block won't change the result if the args are the same
|
229
|
+
(@__memoized_#{meth}_cache ||= {})[a] ||= __memoized__#{meth}(*a, &b)
|
230
|
+
end
|
231
|
+
EOF
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -108,6 +108,36 @@ class String
|
|
108
108
|
alias_method :chomp_lines, :each_chomped
|
109
109
|
|
110
110
|
|
111
|
+
def split_at(boundary, options={})
|
112
|
+
include_boundary = options[:include_boundary] || false
|
113
|
+
|
114
|
+
boundary = Regexp.new(Regexp.escape(boundary)) if boundary.is_a?(String)
|
115
|
+
s = StringScanner.new(self)
|
116
|
+
|
117
|
+
Enumerator.new do |yielder|
|
118
|
+
loop do
|
119
|
+
if match = s.scan_until(boundary)
|
120
|
+
if include_boundary
|
121
|
+
yielder << match
|
122
|
+
else
|
123
|
+
yielder << match[0..-(s.matched_size+1)]
|
124
|
+
end
|
125
|
+
else
|
126
|
+
yielder << s.rest if s.rest?
|
127
|
+
break
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def split_after(boundary)
|
134
|
+
split_at(boundary, include_boundary: true)
|
135
|
+
end
|
136
|
+
|
137
|
+
def split_before(boundary)
|
138
|
+
raise "Why would you want this? Sorry, unimplemented. Send patches."
|
139
|
+
end
|
140
|
+
|
111
141
|
#
|
112
142
|
# Indent all the lines, if "prefix" is a string, prepend that string
|
113
143
|
# to each lien. If it's an integer, prepend that many spaces.
|
@@ -199,9 +229,12 @@ class String
|
|
199
229
|
end
|
200
230
|
alias_method :wrapdent, :wrap_and_indent
|
201
231
|
|
232
|
+
def sentences
|
233
|
+
split_after(/[\.\!\?]+/).lazy.map {|s| s.strip.gsub(/\s+/, " ") }
|
234
|
+
end
|
235
|
+
|
202
236
|
def words
|
203
|
-
scan
|
204
|
-
# scan /^[a-z]+$|^\w+\-\w+|^[a-z]+[0-9]+[a-z]+$|^[0-9]+[a-z]+|^[a-z]+[0-9]+$/
|
237
|
+
scan /[[:alnum:]]+/
|
205
238
|
end
|
206
239
|
|
207
240
|
def words_without_stopwords
|
data/spec/core_ext_spec.rb
CHANGED
@@ -300,6 +300,8 @@ describe String do
|
|
300
300
|
it "wordses" do
|
301
301
|
s = "This, is a bunch, of words."
|
302
302
|
s.words.should == ["This", "is", "a", "bunch", "of", "words"]
|
303
|
+
|
304
|
+
"Weird word-like things".words.should == ["Weird", "word", "like", "things"]
|
303
305
|
end
|
304
306
|
|
305
307
|
it "wordses without stopwords" do
|
@@ -355,6 +357,25 @@ describe String do
|
|
355
357
|
little_endian_bytes.to_i_from_bytes.should == i
|
356
358
|
end
|
357
359
|
|
360
|
+
it "split_ats" do
|
361
|
+
"hello@@there@@whee".split_at("@@").to_a.should == ["hello", "there", "whee"]
|
362
|
+
"hello".split_at("@@").to_a.should == ["hello"]
|
363
|
+
"whatAAAtheBBBheck???oic".split_at(/[AB\?]{1,3}/).to_a.should == ["what", "the", "heck", "oic"]
|
364
|
+
"hello@there".split_after("@").to_a.should == ["hello@", "there"]
|
365
|
+
"line\nline\n".split_at("\n", include_boundary: true).to_a.should == ["line\n", "line\n"]
|
366
|
+
end
|
367
|
+
|
368
|
+
it "sentences" do
|
369
|
+
string = "Sentence the first. Sentence\nthe second. Sentence the third!!!\n\nThe end."
|
370
|
+
|
371
|
+
string.sentences.to_a.should == [
|
372
|
+
"Sentence the first.",
|
373
|
+
"Sentence the second.",
|
374
|
+
"Sentence the third!!!",
|
375
|
+
"The end.",
|
376
|
+
]
|
377
|
+
end
|
378
|
+
|
358
379
|
end
|
359
380
|
|
360
381
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.113
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.7.
|
134
|
+
rubygems_version: 2.7.7
|
135
135
|
signing_key:
|
136
136
|
specification_version: 3
|
137
137
|
summary: Not utils... METILS!
|