map_by_method 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/map_by_method/version.rb +1 -1
- data/lib/map_by_method.rb +2 -2
- data/test/map_by_method_test.rb +31 -0
- metadata +3 -2
data/lib/map_by_method.rb
CHANGED
@@ -8,9 +8,9 @@ module MapByMethod
|
|
8
8
|
rescue NoMethodError
|
9
9
|
error = $!
|
10
10
|
begin
|
11
|
-
re = /(map|collect|select|each|reject)_([\\w\\_]+\\??)/
|
11
|
+
re = /(map|collect|select|each|reject)(_by)?_([\\w\\_]+\\??)/
|
12
12
|
if (match = method.to_s.match(re))
|
13
|
-
iterator, callmethod = match[1
|
13
|
+
iterator, callmethod = match[1], match[3]
|
14
14
|
return self.send(iterator) {|item| item.send callmethod}
|
15
15
|
end
|
16
16
|
return self.map {|item| item.send method.to_s.singularize.to_sym}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class MapByMethodTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_map
|
9
|
+
assert_equal ['1','2','3'], [1,2,3].map_to_s
|
10
|
+
assert_equal ['1','2','3'], [1,2,3].map_by_to_s
|
11
|
+
assert_equal ['1','2','3'], [1,2,3].to_ss
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_collect
|
15
|
+
assert_equal ['1','2','3'], [1,2,3].collect_to_s
|
16
|
+
assert_equal ['1','2','3'], [1,2,3].collect_by_to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_reject
|
20
|
+
assert_equal [1,3], [1,nil,3].reject_nil?
|
21
|
+
assert_equal [1,3], [1,nil,3].reject_by_nil?
|
22
|
+
assert_equal [1,3], [1,0,3].reject_zero?
|
23
|
+
assert_equal [1,3], [1,0,3].reject_by_zero?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_select
|
27
|
+
assert_equal [nil], [1,nil,3].select_nil?
|
28
|
+
assert_equal ['1','3'], ['1','','3'].select_any?
|
29
|
+
assert_equal ['1','3'], ['1','','3'].select_by_any?
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: map_by_method
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-10-
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2006-10-11 00:00:00 +02:00
|
8
8
|
summary: description of gem
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- Rakefile
|
34
34
|
- test/all_tests.rb
|
35
35
|
- test/test_helper.rb
|
36
|
+
- test/map_by_method_test.rb
|
36
37
|
- lib/map_by_method.rb
|
37
38
|
- lib/map_by_method
|
38
39
|
- lib/map_by_method/version.rb
|