Method_Name 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Method_Name/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Method_Name"
8
+ s.version = Method_Name::VERSION
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = "https://github.com/da99/Method_Name"
12
+ s.summary = %q{Extract method names from strings.}
13
+ s.description = %q{
14
+ A Ruby gem to turn strings into method names for
15
+ your metaprogramming needs.
16
+ }
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency 'bacon'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'Bacon_Colored'
26
+ s.add_development_dependency 'pry'
27
+
28
+ # Specify any dependencies here; for example:
29
+ # s.add_runtime_dependency 'rest-client'
30
+ end
@@ -0,0 +1,32 @@
1
+
2
+ Method\_Name
3
+ ================
4
+
5
+ A Ruby gem to turn strings into method names for
6
+ your metaprogramming needs.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install Method_Name
12
+
13
+ Usage
14
+ ------
15
+
16
+ require "Method_Name"
17
+
18
+ Method_Name? "file" # -> true
19
+ Method_Name? "file.sh" # -> false
20
+ Method_Name " dir/file.sh " # -> "file_sh"
21
+
22
+
23
+ Run Tests
24
+ ---------
25
+
26
+ git clone git@github.com:da99/Method_Name.git
27
+ cd Method_Name
28
+ bundle update
29
+ bundle exec bacon spec/main.rb
30
+
31
+
32
+
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ require 'Method_Name/version'
2
+
3
+ def Method_Name? str
4
+
5
+ return false if str[' ']
6
+ return true unless str[Method_Name::INVALID_REGEXP]
7
+
8
+ begin
9
+ eval %!
10
+ class Method_Name
11
+ module Sandbox
12
+ def #{str}
13
+ end
14
+ end
15
+ end
16
+ !
17
+
18
+ true
19
+ rescue Object => e
20
+ false
21
+ end
22
+
23
+ end # === def Method_Name
24
+
25
+ def Method_Name str
26
+
27
+ File.basename(str.strip.downcase)
28
+ .gsub( %r!#{Method_Name::INVALID_REGEXP}+!, '_' )
29
+
30
+ end # === def Method_Name
31
+
32
+ class Method_Name
33
+
34
+ INVALID_REGEXP = %r![^a-z0-9\_]!i
35
+
36
+ end # === class Method_Name
@@ -0,0 +1,3 @@
1
+ class Method_Name
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.print e.message, "\n"
7
+ $stderr.print "Run `bundle install` to install missing gems\n"
8
+ exit e.status_code
9
+ end
10
+ require 'bacon'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ Bacon.summary_on_exit
@@ -0,0 +1,15 @@
1
+
2
+ require File.expand_path('spec/helper')
3
+ require 'Method_Name'
4
+ require 'Bacon_Colored'
5
+ require 'pry'
6
+
7
+
8
+ # ======== Include the tests.
9
+ if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
10
+ # Do nothing. Bacon grabs the file.
11
+ else
12
+ Dir.glob('spec/tests/*.rb').each { |file|
13
+ require File.expand_path(file.sub('.rb', '')) if File.file?(file)
14
+ }
15
+ end
@@ -0,0 +1,41 @@
1
+
2
+ describe "Method_Name?" do
3
+
4
+ it "returns true if string only has: a-z A-Z 0-9 \_" do
5
+ Method_Name?('a_z_0_9').should == true
6
+ end
7
+
8
+ it "returns false if string has invalid characters: - . " do
9
+ Method_Name?('a-z-0.9').should == false
10
+ end
11
+
12
+ it "returns true for '>>'" do
13
+ Method_Name?('>>').should == true
14
+ end
15
+
16
+ it "returns false if name has a space" do
17
+ Method_Name?("name anem").should == false
18
+ end
19
+
20
+ it "returns false for: $? " do
21
+ Method_Name?("$?").should == false
22
+ end
23
+
24
+ end # === Method_Name?
25
+
26
+ describe "Method_Name" do
27
+
28
+ it "returns a stripped string" do
29
+ Method_Name(' str ').should == 'str'
30
+ end
31
+
32
+ it "applies File.basename on string" do
33
+ Method_Name('/dir/file').should == 'file'
34
+ end
35
+
36
+ it "replaces consecutive invalid characters with underscore: a--b--c" do
37
+ Method_Name('a--b--c').should == 'a_b_c'
38
+ end
39
+
40
+ end # === Method_Name
41
+
@@ -0,0 +1,13 @@
1
+
2
+ bins = Dir.glob("bin/*")
3
+
4
+ unless bins.empty?
5
+ describe "permissions of bin/" do
6
+ bins.each { |file|
7
+ it "should chmod 755 for: #{file}" do
8
+ `stat -c %a #{file}`.strip
9
+ .should.be == "755"
10
+ end
11
+ }
12
+ end # === permissions of bin/
13
+ end # === unless bins.empty?
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Method_Name
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: Bacon_Colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! "\n A Ruby gem to turn strings into method names for \n your
79
+ metaprogramming needs.\n "
80
+ email:
81
+ - i-hate-spam-45671204@mailinator.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - Method_Name.gemspec
89
+ - README.md
90
+ - Rakefile
91
+ - lib/Method_Name.rb
92
+ - lib/Method_Name/version.rb
93
+ - spec/helper.rb
94
+ - spec/main.rb
95
+ - spec/tests/Method_Name.rb
96
+ - spec/tests/bin.rb
97
+ homepage: https://github.com/da99/Method_Name
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.23
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Extract method names from strings.
121
+ test_files: []