epitools 0.5.103 → 0.5.105
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/Rakefile +2 -2
- data/TODO +1 -1
- data/VERSION +1 -1
- data/lib/epitools.rb +1 -1
- data/lib/epitools/colored.rb +25 -25
- data/lib/epitools/core_ext/enumerable.rb +1 -1
- data/lib/epitools/core_ext/file.rb +6 -2
- data/lib/epitools/core_ext/hash.rb +43 -29
- data/lib/epitools/core_ext/misc.rb +21 -1
- data/lib/epitools/core_ext/object.rb +19 -19
- data/lib/epitools/core_ext/truthiness.rb +5 -5
- data/lib/epitools/daemonize.rb +1 -1
- data/lib/epitools/hexdump.rb +1 -1
- data/lib/epitools/iter.rb +26 -26
- data/lib/epitools/lcs.rb +3 -3
- data/lib/epitools/mimemagic.rb +7 -7
- data/lib/epitools/niceprint.rb +18 -18
- data/lib/epitools/numwords.rb +34 -34
- data/lib/epitools/path.rb +7 -0
- data/lib/epitools/permutations.rb +9 -9
- data/lib/epitools/pretty_backtrace.rb +11 -11
- data/lib/epitools/progressbar.rb +7 -7
- data/lib/epitools/rails.rb +2 -2
- data/lib/epitools/rash.rb +16 -16
- data/lib/epitools/ratio.rb +1 -1
- data/lib/epitools/sys.rb +47 -47
- data/lib/epitools/trie.rb +4 -4
- data/lib/epitools/typed_struct.rb +5 -5
- data/lib/epitools/wm.rb +6 -6
- data/lib/epitools/zopen.rb +2 -2
- data/spec/autoreq_spec.rb +5 -5
- data/spec/browser_spec.rb +1 -1
- data/spec/colored_spec.rb +5 -5
- data/spec/core_ext_spec.rb +1 -1
- data/spec/histogram_spec.rb +3 -3
- data/spec/iter_spec.rb +16 -16
- data/spec/lcs_spec.rb +5 -5
- data/spec/numwords_spec.rb +8 -8
- data/spec/permutations_spec.rb +9 -9
- data/spec/rash_spec.rb +7 -7
- data/spec/ratio_spec.rb +5 -5
- data/spec/sys_spec.rb +6 -6
- data/spec/term_spec.rb +7 -7
- data/spec/typed_struct_spec.rb +5 -5
- data/spec/wm_spec.rb +4 -4
- data/spec/zopen_spec.rb +11 -11
- 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: d427d1b5d8c2314e24298cf32b86887e9f4592c3
|
4
|
+
data.tar.gz: 7e4ba5fbe4bdb2b3f07484f63f53fec7dba23389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56cfdcaf9cc2b1d56e41a0eacad29c004cdf675f996a4281074f714dee52435c5dcd062b61d7ba0f32930b10044d7cbfb318670eea8b1a6a6d8f970953fdcd61
|
7
|
+
data.tar.gz: 442b4209f5caf2d85b3a90980d15e4a7114d2521eda593e8f641c29674617e5f6914f33a445c014dd35887fb3c88193d336b3f9c4327c50e3dd648b84864db5b
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Useful miscellaneous improvements for base Ruby objects, plus some extra
|
|
4
4
|
data structures and handy wrappers. You can think of it as a light-weight
|
5
5
|
ActiveSupport.
|
6
6
|
|
7
|
-
All epitools modules (and a bunch of Ruby's stdlib) are
|
7
|
+
All epitools modules (and a bunch of Ruby's stdlib) are
|
8
8
|
{loaded on demand with "autoload"}[https://github.com/epitron/epitools/blob/master/lib/epitools/autoloads.rb],
|
9
9
|
so it's really fast. (Require this in your .irbrc or .pryrc, and you'll never have to require another Ruby stdlib module again!)
|
10
10
|
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ gem_version = File.read("VERSION").strip
|
|
3
3
|
task :build do
|
4
4
|
system "gem build .gemspec"
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
task :release => :build do
|
8
8
|
system "gem push epitools-#{gem_version}.gem"
|
9
9
|
end
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
task :spec do
|
20
20
|
cmd = %w[rspec -fd -c spec]
|
21
|
-
|
21
|
+
|
22
22
|
if system *%w[which rescue]
|
23
23
|
system *(["rescue"]+cmd)
|
24
24
|
else
|
data/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.105
|
data/lib/epitools.rb
CHANGED
data/lib/epitools/colored.rb
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
#
|
33
33
|
# Since the presence of a terminal is detected automatically, the colors will be
|
34
34
|
# disabled when you pipe your program to another program. However, if you want to
|
35
|
-
# show colors when piped (eg: when you pipe to `less -R`), you can force it:
|
35
|
+
# show colors when piped (eg: when you pipe to `less -R`), you can force it:
|
36
36
|
#
|
37
37
|
# >> Colored.enable!
|
38
38
|
# >> Colored.disable!
|
@@ -49,10 +49,10 @@ module Colored
|
|
49
49
|
|
50
50
|
@@is_tty = STDOUT.isatty
|
51
51
|
|
52
|
-
COLORS = {
|
52
|
+
COLORS = {
|
53
53
|
'black' => 30,
|
54
|
-
'red' => 31,
|
55
|
-
'green' => 32,
|
54
|
+
'red' => 31,
|
55
|
+
'green' => 32,
|
56
56
|
'yellow' => 33,
|
57
57
|
'blue' => 34,
|
58
58
|
'magenta' => 35,
|
@@ -62,13 +62,13 @@ module Colored
|
|
62
62
|
}
|
63
63
|
|
64
64
|
EXTRAS = {
|
65
|
-
'clear' => 0,
|
65
|
+
'clear' => 0,
|
66
66
|
'bold' => 1,
|
67
67
|
'light' => 1,
|
68
68
|
'underline' => 4,
|
69
69
|
'reversed' => 7
|
70
70
|
}
|
71
|
-
|
71
|
+
|
72
72
|
#
|
73
73
|
# BBS-style numeric color codes.
|
74
74
|
#
|
@@ -99,9 +99,9 @@ module Colored
|
|
99
99
|
|
100
100
|
Set.new(normal + lights + brights + on_backgrounds + ["grey", "gray"])
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
COLORS.each do |color, value|
|
104
|
-
define_method(color) do
|
104
|
+
define_method(color) do
|
105
105
|
colorize(self, :foreground => color)
|
106
106
|
end
|
107
107
|
|
@@ -133,10 +133,10 @@ module Colored
|
|
133
133
|
|
134
134
|
alias_method :gray, :light_black
|
135
135
|
alias_method :grey, :light_black
|
136
|
-
|
136
|
+
|
137
137
|
EXTRAS.each do |extra, value|
|
138
138
|
next if extra == 'clear'
|
139
|
-
define_method(extra) do
|
139
|
+
define_method(extra) do
|
140
140
|
colorize(self, :extra => extra)
|
141
141
|
end
|
142
142
|
end
|
@@ -173,7 +173,7 @@ module Colored
|
|
173
173
|
if string == nil
|
174
174
|
return self.tagged_colors
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
if @@is_tty
|
178
178
|
colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * ''
|
179
179
|
colored << string
|
@@ -221,7 +221,7 @@ module Colored
|
|
221
221
|
background = color_name.to_s =~ /on_/
|
222
222
|
color_name = color_name.to_s.sub('on_', '')
|
223
223
|
return unless color_name && COLORS[color_name]
|
224
|
-
"\e[#{COLORS[color_name] + (background ? 10 : 0)}m"
|
224
|
+
"\e[#{COLORS[color_name] + (background ? 10 : 0)}m"
|
225
225
|
end
|
226
226
|
|
227
227
|
#
|
@@ -231,7 +231,7 @@ module Colored
|
|
231
231
|
@@is_tty
|
232
232
|
end
|
233
233
|
|
234
|
-
alias_method :is_tty?, :enabled?
|
234
|
+
alias_method :is_tty?, :enabled?
|
235
235
|
|
236
236
|
#
|
237
237
|
# Color commands will always produce colored strings, regardless
|
@@ -240,7 +240,7 @@ module Colored
|
|
240
240
|
def enable!
|
241
241
|
@@is_tty = true
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
244
|
alias_method :force!, :enable!
|
245
245
|
|
246
246
|
#
|
@@ -263,12 +263,12 @@ module Colored
|
|
263
263
|
|
264
264
|
#
|
265
265
|
# Is this string legal?
|
266
|
-
#
|
266
|
+
#
|
267
267
|
def valid_tag?(tag)
|
268
268
|
VALID_COLORS.include?(tag) or
|
269
269
|
(tag =~ /^\d+$/ and BBS_COLOR_TABLE.include?(tag.to_i) )
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
#
|
273
273
|
# Colorize a string that has "color tags".
|
274
274
|
#
|
@@ -278,18 +278,18 @@ module Colored
|
|
278
278
|
# split the string into tags and literal strings
|
279
279
|
tokens = self.split(/(<\/?[\w\d_]+>)/)
|
280
280
|
tokens.delete_if { |token| token.size == 0 }
|
281
|
-
|
281
|
+
|
282
282
|
result = ""
|
283
283
|
|
284
284
|
tokens.each do |token|
|
285
285
|
|
286
286
|
# token is an opening tag!
|
287
|
-
|
287
|
+
|
288
288
|
if /<([\w\d_]+)>/ =~ token and valid_tag?($1)
|
289
289
|
stack.push $1
|
290
290
|
|
291
|
-
# token is a closing tag!
|
292
|
-
|
291
|
+
# token is a closing tag!
|
292
|
+
|
293
293
|
elsif /<\/([\w\d_]+)>/ =~ token and valid_tag?($1)
|
294
294
|
|
295
295
|
# if this color is on the stack somwehere...
|
@@ -301,19 +301,19 @@ module Colored
|
|
301
301
|
end
|
302
302
|
|
303
303
|
# token is a literal string!
|
304
|
-
|
304
|
+
|
305
305
|
else
|
306
306
|
|
307
307
|
color = (stack.last || "white")
|
308
308
|
color = BBS_COLOR_TABLE[color.to_i] if color =~ /^\d+$/
|
309
309
|
result << token.send(color)
|
310
|
-
|
310
|
+
|
311
311
|
end
|
312
|
-
|
312
|
+
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
result
|
316
|
-
end
|
316
|
+
end
|
317
317
|
|
318
318
|
end unless Object.const_defined? :Colored
|
319
319
|
|
@@ -102,7 +102,7 @@ class File
|
|
102
102
|
# Scan through the file until `string` is found, and set the IO's +pos+ to the first character of the matched string.
|
103
103
|
#
|
104
104
|
def seek_to(string, blocksize=512)
|
105
|
-
raise "Error: blocksize must be at least as large as the string" if string.size
|
105
|
+
raise "Error: blocksize must be at least as large as the string" if blocksize < string.size
|
106
106
|
|
107
107
|
loop do
|
108
108
|
data = read(blocksize)
|
@@ -116,13 +116,15 @@ class File
|
|
116
116
|
seek(-(string.size - 1), IO::SEEK_CUR)
|
117
117
|
end
|
118
118
|
end
|
119
|
+
|
120
|
+
pos
|
119
121
|
end
|
120
122
|
|
121
123
|
#
|
122
124
|
# Scan backwards in the file until `string` is found, and set the IO's +pos+ to the first character after the matched string.
|
123
125
|
#
|
124
126
|
def seek_backwards_to(string, blocksize=512, rindex_end=-1)
|
125
|
-
raise "Error: blocksize must be at least as large as the string" if string.size
|
127
|
+
raise "Error: blocksize must be at least as large as the string" if blocksize < string.size
|
126
128
|
|
127
129
|
loop do
|
128
130
|
data = reverse_read(blocksize)
|
@@ -136,6 +138,8 @@ class File
|
|
136
138
|
seek(string.size - 1, IO::SEEK_CUR)
|
137
139
|
end
|
138
140
|
end
|
141
|
+
|
142
|
+
pos
|
139
143
|
end
|
140
144
|
alias_method :reverse_seek_to, :seek_backwards_to
|
141
145
|
|
@@ -7,15 +7,15 @@ class Hash
|
|
7
7
|
def blank?
|
8
8
|
not any?
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# Runs "remove_blank_values" on self.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
def remove_blank_values!
|
15
15
|
delete_if{|k,v| v.blank?}
|
16
16
|
self
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
#
|
20
20
|
# Returns a new Hash where blank values have been removed.
|
21
21
|
# (It checks if the value is blank by calling #blank? on it)
|
@@ -23,10 +23,10 @@ class Hash
|
|
23
23
|
def remove_blank_values
|
24
24
|
dup.remove_blank_values!
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
#
|
28
|
+
# Runs map_values on self.
|
27
29
|
#
|
28
|
-
# Runs map_values on self.
|
29
|
-
#
|
30
30
|
def map_values!(&block)
|
31
31
|
keys.each do |key|
|
32
32
|
value = self[key]
|
@@ -34,7 +34,7 @@ class Hash
|
|
34
34
|
end
|
35
35
|
self
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
#
|
39
39
|
# Transforms the values of the hash by passing them into the supplied
|
40
40
|
# block, and then using the block's result as the new value.
|
@@ -45,7 +45,7 @@ class Hash
|
|
45
45
|
|
46
46
|
#
|
47
47
|
# Runs map_keys on self.
|
48
|
-
#
|
48
|
+
#
|
49
49
|
def map_keys!(&block)
|
50
50
|
keys.each do |key|
|
51
51
|
value = delete(key)
|
@@ -53,7 +53,7 @@ class Hash
|
|
53
53
|
end
|
54
54
|
self
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
#
|
58
58
|
# Transforms the keys of the hash by passing them into the supplied block,
|
59
59
|
# and then using the blocks result as the new key.
|
@@ -62,6 +62,20 @@ class Hash
|
|
62
62
|
dup.map_keys!(&block)
|
63
63
|
end
|
64
64
|
|
65
|
+
#
|
66
|
+
# Convert the keys to symbols in-place, for fun and profit
|
67
|
+
#
|
68
|
+
def symbolize_keys!
|
69
|
+
map_keys! { |k| k.to_sym }
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Return a hash with its keys converted to symbols, for great justice
|
74
|
+
#
|
75
|
+
def symbolize_keys
|
76
|
+
dup.symbolize_keys!
|
77
|
+
end
|
78
|
+
|
65
79
|
#
|
66
80
|
# Returns a hash containing only the keys passed as arguments.
|
67
81
|
#
|
@@ -140,14 +154,14 @@ class Hash
|
|
140
154
|
end
|
141
155
|
end
|
142
156
|
end
|
143
|
-
end
|
144
|
-
|
157
|
+
end
|
158
|
+
|
145
159
|
#
|
146
160
|
# `key?` and `includes?` is an alias for `include?`
|
147
|
-
#
|
161
|
+
#
|
148
162
|
alias_method :key?, :include?
|
149
163
|
alias_method :includes?, :include?
|
150
|
-
|
164
|
+
|
151
165
|
#
|
152
166
|
# Makes each element in the `path` array point to a hash containing the next element in the `path`.
|
153
167
|
# Useful for turning a bunch of strings (paths, module names, etc.) into a tree.
|
@@ -164,7 +178,7 @@ class Hash
|
|
164
178
|
self[dir].mkdir_p(path[1..-1])
|
165
179
|
self
|
166
180
|
end
|
167
|
-
|
181
|
+
|
168
182
|
#
|
169
183
|
# Turn some nested hashes into a tree (returns an array of strings, padded on the left with indents.)
|
170
184
|
#
|
@@ -176,8 +190,8 @@ class Hash
|
|
176
190
|
result += val.tree(level+1) if val.any?
|
177
191
|
end
|
178
192
|
result
|
179
|
-
end
|
180
|
-
|
193
|
+
end
|
194
|
+
|
181
195
|
#
|
182
196
|
# Print the result of `tree`
|
183
197
|
#
|
@@ -188,15 +202,15 @@ class Hash
|
|
188
202
|
puts block_given? ? yield(key, level) : "#{dent}#{key}"
|
189
203
|
val.print_tree(level+1, indent, &block) if val.any?
|
190
204
|
end
|
191
|
-
end
|
192
|
-
|
205
|
+
end
|
206
|
+
|
193
207
|
#
|
194
208
|
# Convert the hash into a GET query.
|
195
209
|
#
|
196
210
|
def to_query
|
197
211
|
params = ''
|
198
212
|
stack = []
|
199
|
-
|
213
|
+
|
200
214
|
each do |k, v|
|
201
215
|
if v.is_a?(Hash)
|
202
216
|
stack << [k,v]
|
@@ -204,7 +218,7 @@ class Hash
|
|
204
218
|
params << "#{k}=#{v}&"
|
205
219
|
end
|
206
220
|
end
|
207
|
-
|
221
|
+
|
208
222
|
stack.each do |parent, hash|
|
209
223
|
hash.each do |k, v|
|
210
224
|
if v.is_a?(Hash)
|
@@ -214,15 +228,15 @@ class Hash
|
|
214
228
|
end
|
215
229
|
end
|
216
230
|
end
|
217
|
-
|
231
|
+
|
218
232
|
params.chop! # trailing &
|
219
233
|
params
|
220
234
|
end
|
221
|
-
|
235
|
+
|
222
236
|
#
|
223
237
|
# Query a hash using MQL (see: http://wiki.freebase.com/wiki/MQL_operators for reference)
|
224
238
|
#
|
225
|
-
# Examples:
|
239
|
+
# Examples:
|
226
240
|
# > query(name: /steve/)
|
227
241
|
# > query(/title/ => ??)
|
228
242
|
# > query(articles: [{title: ??}])
|
@@ -230,21 +244,21 @@ class Hash
|
|
230
244
|
# > query("date_of_birth<" => "2000")
|
231
245
|
#
|
232
246
|
def query(template)
|
233
|
-
results = []
|
247
|
+
results = []
|
234
248
|
template.each do |key,val|
|
235
249
|
case key
|
236
250
|
when Regexp, String
|
237
251
|
when Array
|
238
252
|
when Hash
|
239
|
-
results += hash.query(template)
|
253
|
+
results += hash.query(template)
|
240
254
|
end
|
241
255
|
end
|
242
|
-
|
256
|
+
|
243
257
|
map do |key,val|
|
244
|
-
end
|
258
|
+
end
|
245
259
|
end
|
246
260
|
alias_method :mql, :query
|
247
|
-
|
261
|
+
|
248
262
|
|
249
263
|
#
|
250
264
|
# Return all the changes necessary to transform `self` into `other`. (Works on nested hashes.) The result is a hash of {:key => [old value, new value]} pairs.
|
@@ -257,7 +271,7 @@ class Hash
|
|
257
271
|
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash)
|
258
272
|
memo[key] = self[key].diff(other[key])
|
259
273
|
else
|
260
|
-
memo[key] = [self[key], other[key]]
|
274
|
+
memo[key] = [self[key], other[key]]
|
261
275
|
end
|
262
276
|
end
|
263
277
|
memo
|