Method_Name 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/Method_Name.rb +11 -7
- data/lib/Method_Name/version.rb +1 -1
- data/spec/tests/Method_Name.rb +12 -0
- metadata +1 -1
data/lib/Method_Name.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'Method_Name/version'
|
2
2
|
|
3
|
-
def Method_Name?
|
4
|
-
|
5
|
-
return false if
|
6
|
-
return
|
3
|
+
def Method_Name? raw_name
|
4
|
+
name = raw_name.to_s
|
5
|
+
return false if name[' ']
|
6
|
+
return false if name.to_s.strip.empty?
|
7
|
+
return true unless name[Method_Name::INVALID_REGEXP]
|
7
8
|
|
8
9
|
begin
|
9
10
|
eval %!
|
10
11
|
class Method_Name
|
11
12
|
module Sandbox
|
12
|
-
def #{
|
13
|
+
def #{name}
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -22,10 +23,13 @@ def Method_Name? str
|
|
22
23
|
|
23
24
|
end # === def Method_Name
|
24
25
|
|
25
|
-
def Method_Name
|
26
|
+
def Method_Name name
|
26
27
|
|
27
|
-
File.basename(
|
28
|
+
new_name = File.basename(name.strip.downcase)
|
28
29
|
.gsub( %r!#{Method_Name::INVALID_REGEXP}+!, '_' )
|
30
|
+
|
31
|
+
return nil unless Method_Name?(new_name)
|
32
|
+
new_name
|
29
33
|
|
30
34
|
end # === def Method_Name
|
31
35
|
|
data/lib/Method_Name/version.rb
CHANGED
data/spec/tests/Method_Name.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
|
2
2
|
describe "Method_Name?" do
|
3
3
|
|
4
|
+
it "accepts a symbol as a valid argument" do
|
5
|
+
Method_Name?(:<<).should == true
|
6
|
+
end
|
7
|
+
|
4
8
|
it "returns true if string only has: a-z A-Z 0-9 \_" do
|
5
9
|
Method_Name?('a_z_0_9').should == true
|
6
10
|
end
|
@@ -20,6 +24,10 @@ describe "Method_Name?" do
|
|
20
24
|
it "returns false for: $? " do
|
21
25
|
Method_Name?("$?").should == false
|
22
26
|
end
|
27
|
+
|
28
|
+
it "returns false for: ''" do
|
29
|
+
Method_Name?('').should == false
|
30
|
+
end
|
23
31
|
|
24
32
|
end # === Method_Name?
|
25
33
|
|
@@ -36,6 +44,10 @@ describe "Method_Name" do
|
|
36
44
|
it "replaces consecutive invalid characters with underscore: a--b--c" do
|
37
45
|
Method_Name('a--b--c').should == 'a_b_c'
|
38
46
|
end
|
47
|
+
|
48
|
+
it "returns nil if a valid method name can not be extracted" do
|
49
|
+
Method_Name('').should == nil
|
50
|
+
end
|
39
51
|
|
40
52
|
end # === Method_Name
|
41
53
|
|