epitools 0.5.3 → 0.5.4
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.
- data/VERSION +1 -1
- data/epitools.gemspec +2 -2
- data/lib/epitools/clitools.rb +8 -3
- data/lib/epitools/colored.rb +9 -10
- data/lib/epitools/core_ext.rb +1 -3
- data/lib/epitools/core_ext/enumerable.rb +17 -7
- data/lib/epitools/core_ext/numbers.rb +1 -1
- data/spec/clitools_spec.rb +5 -0
- data/spec/colored_spec.rb +2 -1
- data/spec/core_ext_spec.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.4
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "epitools"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = "2012-04-
|
12
|
+
s.date = "2012-04-28"
|
13
13
|
s.description = "Miscellaneous utility libraries to make my life easier."
|
14
14
|
s.email = "chris@ill-logic.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/epitools/clitools.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'epitools/colored'
|
2
2
|
|
3
3
|
class String
|
4
4
|
|
@@ -8,9 +8,14 @@ class String
|
|
8
8
|
#
|
9
9
|
# The pattern can be a string or a regular expression.
|
10
10
|
#
|
11
|
-
def highlight(pattern, color=:light_yellow)
|
11
|
+
def highlight(pattern, color=:light_yellow, &block)
|
12
12
|
pattern = Regexp.new(Regexp.escape(pattern)) if pattern.is_a? String
|
13
|
-
|
13
|
+
|
14
|
+
if block_given?
|
15
|
+
gsub(pattern, &block)
|
16
|
+
else
|
17
|
+
gsub(pattern) { |match| match.send(color) }
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
end
|
data/lib/epitools/colored.rb
CHANGED
@@ -91,12 +91,14 @@ module Colored
|
|
91
91
|
15 => :light_white,
|
92
92
|
}
|
93
93
|
|
94
|
-
VALID_COLORS =
|
95
|
-
COLORS.keys
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
VALID_COLORS = begin
|
95
|
+
normal = COLORS.keys
|
96
|
+
lights = normal.map { |fore| "light_#{fore}" }
|
97
|
+
brights = normal.map { |fore| "bright_#{fore}" }
|
98
|
+
on_backgrounds = normal.map { |fore| normal.map { |back| "#{fore}_on_#{back}" } }.flatten
|
99
|
+
|
100
|
+
Set.new(normal + lights + brights + on_backgrounds + ["grey", "gray"])
|
101
|
+
end
|
100
102
|
|
101
103
|
COLORS.each do |color, value|
|
102
104
|
define_method(color) do
|
@@ -248,10 +250,7 @@ module Colored
|
|
248
250
|
#
|
249
251
|
def valid_tag?(tag)
|
250
252
|
VALID_COLORS.include?(tag) or
|
251
|
-
|
252
|
-
tag =~ /^\d+$/ and
|
253
|
-
BBS_COLOR_TABLE.include?(tag.to_i)
|
254
|
-
)
|
253
|
+
(tag =~ /^\d+$/ and BBS_COLOR_TABLE.include?(tag.to_i) )
|
255
254
|
end
|
256
255
|
|
257
256
|
#
|
data/lib/epitools/core_ext.rb
CHANGED
@@ -178,7 +178,7 @@ module Enumerable
|
|
178
178
|
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
alias_method :recursive_map, :deep_map
|
183
183
|
alias_method :map_recursively, :deep_map
|
184
184
|
alias_method :map_recursive, :deep_map
|
@@ -188,16 +188,26 @@ module Enumerable
|
|
188
188
|
# recursively on that element.
|
189
189
|
#
|
190
190
|
# Example:
|
191
|
-
# [ [1,2], [3,4] ].
|
191
|
+
# [ [1,2], [3,4] ].deep_select{|e| e % 2 == 0 } #=> [ [2], [4] ]
|
192
192
|
#
|
193
193
|
def deep_select(depth=nil, &block)
|
194
|
-
|
195
|
-
|
196
|
-
|
194
|
+
map do |*args|
|
195
|
+
|
196
|
+
if depth.nil? or depth > 0
|
197
|
+
|
198
|
+
case obj
|
199
|
+
when Hash
|
200
|
+
|
201
|
+
when Array, Enumerable
|
202
|
+
result = obj.deep_select(depth ? depth-1 : nil, &block)
|
203
|
+
result.any? ? result : nil
|
204
|
+
end
|
205
|
+
|
197
206
|
else
|
198
|
-
block.call(
|
207
|
+
obj if block.call(obj)
|
199
208
|
end
|
200
|
-
|
209
|
+
|
210
|
+
end.compact
|
201
211
|
end
|
202
212
|
|
203
213
|
alias_method :recursive_select, :deep_select
|
data/spec/clitools_spec.rb
CHANGED
@@ -11,6 +11,11 @@ describe String do
|
|
11
11
|
"xxxmatchzzz".highlight(/m.+h/, color).should == highlighted
|
12
12
|
"xxxmatchzzz".highlight(/MATCH/i, color).should == highlighted
|
13
13
|
end
|
14
|
+
|
15
|
+
it "highlights with a block" do
|
16
|
+
result = "xxxmatchxxx".highlight(/match/) { |match| "<8>#{match}</8>" }
|
17
|
+
result.should == "xxx<8>match</8>xxx"
|
18
|
+
end
|
14
19
|
|
15
20
|
it "cmds" do
|
16
21
|
cmd( ['test -f ?', __FILE__] ).should == true
|
data/spec/colored_spec.rb
CHANGED
@@ -23,7 +23,8 @@ describe "Colored strings" do
|
|
23
23
|
"<magenta>hello".colorize.should == "<purple>hello".colorize
|
24
24
|
"<gray>hello".colorize.should == "<light_black>hello".colorize
|
25
25
|
lambda { "</blue>".colorize }.should raise_error
|
26
|
-
|
26
|
+
"<black_on_yellow>hello".colorize.should == "hello".black_on_yellow
|
27
|
+
end
|
27
28
|
|
28
29
|
end
|
29
30
|
|
data/spec/core_ext_spec.rb
CHANGED
@@ -388,7 +388,7 @@ describe Enumerable do
|
|
388
388
|
end
|
389
389
|
|
390
390
|
it "selects deeply" do
|
391
|
-
[[1,2],[3,4]].deep_select {|e| e % 2 == 0 }.should == [2,4]
|
391
|
+
[[1,2],[3,4]].deep_select {|e| e % 2 == 0 }.should == [[2],[4]]
|
392
392
|
{1=>2, 3=>{4=>5, 6=>7}}.deep_select {|k,v| k == 1 }.should == {1=>2}
|
393
393
|
#[1,2,3,4].deep_select {|e| e ** 2}.should == [1,4,9,16]
|
394
394
|
#[[],[],1,2,3,4].deep_select {|e| e ** 2}.should == [[], [], 1, 4, 9, 16]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|