re_expand 0.0.2 → 0.0.3
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/lib/Generator.rb +0 -4
- data/lib/re_expand.rb +17 -14
- data/test/test_re_expand.rb +31 -6
- metadata +3 -3
data/lib/Generator.rb
CHANGED
@@ -114,11 +114,7 @@ module ReExpand
|
|
114
114
|
patstr = (["(.*)"] * sslen).join("\t")
|
115
115
|
/#{patstr}/ =~ ss.join("\t")
|
116
116
|
end
|
117
|
-
## next if $1 == $2
|
118
117
|
# 'set date #{$2}' のような記述の$変数にsubstringの値を代入
|
119
|
-
File.open("/tmp/log","a"){ |f|
|
120
|
-
f.puts "#{s}-----" + eval('%('+@commands[acceptno]+')')
|
121
|
-
}
|
122
118
|
res[ambig] << [s, eval('%('+@commands[acceptno]+')')]
|
123
119
|
end
|
124
120
|
end
|
data/lib/re_expand.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
4
|
|
5
5
|
module ReExpand
|
6
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.3'
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'Generator'
|
@@ -15,29 +15,32 @@ class String
|
|
15
15
|
# ExpandHelp用のライブラリを利用
|
16
16
|
def expand(filterpat=' ')
|
17
17
|
g = ReExpand::Generator.new
|
18
|
-
g.add(self,
|
18
|
+
g.add(self,"\#{$1}\t\#{$2}\t\#{$3}\t\#{$4}\t\#{$5}\t\#{$6}\t\#{$7}\t\#{$8}\t\#{$9}")
|
19
19
|
strings = []
|
20
|
+
#if filterpat.class == Regexp && block then
|
21
|
+
# g.generate(' ',block)
|
22
|
+
# return
|
20
23
|
if filterpat.class == String then
|
21
|
-
|
22
|
-
|
23
|
-
strings =
|
24
|
-
r[0]
|
25
|
-
}
|
26
|
-
elsif
|
27
|
-
matched = g.generate(' ')
|
28
|
-
strings = matched[0].collect { |r|
|
24
|
+
m = g.generate(filterpat)
|
25
|
+
matched = m[0].length > 0 ? m[0] : m[1].length > 0 ? m[1] : m[2]
|
26
|
+
strings = matched.collect { |r|
|
29
27
|
r[0]
|
30
28
|
}
|
29
|
+
else
|
30
|
+
matched = g.generate(' ')[0]
|
31
31
|
if filterpat.class == Regexp then
|
32
|
-
|
33
|
-
filterpat.match(
|
32
|
+
matched = matched.find_all { |r|
|
33
|
+
filterpat.match(r[0])
|
34
34
|
}
|
35
35
|
end
|
36
|
+
strings = matched.collect { |r|
|
37
|
+
r[0]
|
38
|
+
}
|
36
39
|
end
|
37
40
|
|
38
41
|
if block_given? then
|
39
|
-
|
40
|
-
yield
|
42
|
+
matched.collect { |m|
|
43
|
+
yield m[0], m[1].split(/\t/)
|
41
44
|
}
|
42
45
|
else
|
43
46
|
strings
|
data/test/test_re_expand.rb
CHANGED
@@ -1,11 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
3
|
|
3
|
-
|
4
|
+
module ReExpand
|
5
|
+
class TestReExpand < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_truth
|
11
|
+
assert true
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_array
|
15
|
+
e = "(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand
|
16
|
+
assert_equal e.class, Array
|
17
|
+
assert_equal e.length, 30
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_2
|
21
|
+
"(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand { |s,a|
|
22
|
+
assert_equal a.length, 2
|
23
|
+
}
|
24
|
+
|
25
|
+
e = "(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand(' 1 ')
|
26
|
+
assert_equal e.length, 5
|
27
|
+
|
28
|
+
'(ab|cd)*'.expand(/bc/){ |s,a|
|
29
|
+
assert_equal a.length, 1
|
30
|
+
assert s =~ /abcd/
|
31
|
+
}
|
32
|
+
|
33
|
+
end
|
4
34
|
|
5
|
-
def setup
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_truth
|
9
|
-
assert true
|
10
35
|
end
|
11
36
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re_expand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Toshiyuki Masui
|