epitools 0.5.112 → 0.5.113

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d59d9daf2f46a0daf7008b75f596bcb8164801c61ec00a8a4f779e3105e97be1
4
- data.tar.gz: 97b7ef67560c7377929db8aece4fc6f7f358f3ef96501c5913f99b75a655fa07
3
+ metadata.gz: ac614574fc21c61b88fb73f208d16c4960c5a3165a78844a56e26c8326e7bf82
4
+ data.tar.gz: 75914fb5972be2115ce1704c896f183300057ab6422be80f7dd50ab5088a152c
5
5
  SHA512:
6
- metadata.gz: c17bdd3fada9128955712952cfa8edfa459ff24f83fd04ba4cef9116c3a931f9caba819095a4131f24c89bc4921d574110f6ccd180310a721c5d072896901e40
7
- data.tar.gz: b642d62d3c9326b2b20a85ebb8bbf92ca5cff1150c6093f7f73530c44b878ef9637a36a8f2649fcac0e4bc22fca1de75469b947f99a648d77082f4d544f08161
6
+ metadata.gz: fd211d087deebafc7fec99003e6dfd20293cac20b9ad7db36cbd03641b1c2b4a4ddb3f1609fd236895cb596444012f5829ee27b2562271d6ca71a1696daaa205
7
+ data.tar.gz: 3c5c750c2767cfc600ae78538ea6339859e8a7c50d4b4b8876efebbbbb658d8a56166e29d50f8a72e72ac12c7e7a7a64a2d179c189f1b3901bc8e26fa4370a09
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.112
1
+ 0.5.113
@@ -21,6 +21,7 @@ autoload :Shellwords, 'shellwords'
21
21
  autoload :PTY, 'pty'
22
22
  autoload :CSV, 'csv'
23
23
  autoload :SDBM, 'sdbm'
24
+ autoload :StringScanner, 'strscan'
24
25
 
25
26
  module Digest
26
27
  autoload :SHA1, 'digest/sha1'
@@ -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 /\w+/
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
@@ -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.112
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-05-02 00:00:00.000000000 Z
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.6
134
+ rubygems_version: 2.7.7
135
135
  signing_key:
136
136
  specification_version: 3
137
137
  summary: Not utils... METILS!