string_in_path 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43d4d1f8b75994a0b9932acd1bd002616c599edf
4
+ data.tar.gz: 76929c5ba769472edb8cf8db6dd33cccfc090858
5
+ SHA512:
6
+ metadata.gz: 50b85075a5d3675775fc97d6152e80176146df8b95d09061d4bba1b25d4e61ea91c66b9996ab01388195a35604381a2c8bce93a82d2f0892d65877f6e04ce664
7
+ data.tar.gz: 73c37a9104bc62e1c63c04d03ed206469c7713b8f2cf3d71be42eafdfaf27d7a60d24e0c556722db1a766a7c82f72643b7e9e5e47bdb1befb5b6b411463ff6a1
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+
17
+ .DS_Store
18
+ /spec/lib/temp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in string_in_path.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # StringInPath
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'string_in_path'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install string_in_path
20
+
21
+ ## Usage
22
+
23
+ ### Recursively check to see if the string "Doppler" is present in any files
24
+ in /home/wbuffett/test:
25
+ StringInFile.present("Doppler", "/home/wbuffett/test")
26
+
27
+ ### Recursively replace every instance of "Doppler" with "Next Generation"
28
+ in all files in /home/wbuffett/test:
29
+ StringInFile.replace("Doppler", "Next Generation", "/home/wbuffett/test")
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/jhsu802701/string_in_path/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,27 @@
1
+ require 'string_in_path/version'
2
+
3
+ module StringInPath
4
+ def self.present (str_to_find, path)
5
+ require 'string_in_file'
6
+ require 'find'
7
+ Find.find(path) do |filename|
8
+ next if filename == ".DS_Store"
9
+ if StringInFile.present(str_to_find,filename) == true
10
+ return true
11
+ end
12
+ end
13
+ return false
14
+ end
15
+
16
+ def self.replace (str1, str2, path)
17
+ require 'string_in_file'
18
+ require 'find'
19
+ Find.find(path) do |filename|
20
+ file_type = `file -b #{filename}`
21
+ if file_type.include?("directory") == false && filename.include?(".DS_Store") == false
22
+ StringInFile.replace(str1, str2, filename)
23
+ system("rm -f #{filename}-e")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module StringInPath
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'string_in_file'
3
+
4
+ describe StringInPath do
5
+ dir_spec_lib = File.expand_path("../", __FILE__)
6
+ dir_parent = "#{dir_spec_lib}/temp"
7
+ dir1 = "#{dir_parent}/dir1"
8
+ dir1a = "#{dir_parent}/dir1/dir1a"
9
+ dir1b = "#{dir_parent}/dir1/dir1b"
10
+ dir2 = "#{dir_parent}/dir2"
11
+ dir2a = "#{dir_parent}/dir2/dir2a"
12
+ dir2b = "#{dir_parent}/dir2/dir2b"
13
+ it "should write text to files" do
14
+ system("mkdir -p #{dir_parent}")
15
+ system("mkdir -p #{dir1}")
16
+ system("mkdir -p #{dir1a}")
17
+ system("mkdir -p #{dir1b}")
18
+ system("mkdir -p #{dir2}")
19
+ system("mkdir -p #{dir2a}")
20
+ system("mkdir -p #{dir2b}")
21
+ StringInFile.write("Chuck Norris can divide by zero.", "#{dir1}/file1.txt")
22
+ StringInFile.write("Chuck Norris can make Grumpy Cat happy.", "#{dir1a}/file1a.txt")
23
+ StringInFile.write("Chuck Norris counted to infinity - twice.", "#{dir1b}/file1b.txt")
24
+ StringInFile.write("Chuck Norris can start a fire by rubbing two ice cubes together.", "#{dir2}/file2.txt")
25
+ StringInFile.write("Waldo is hiding from Chuck Norris.", "#{dir2a}/file2a.txt")
26
+ StringInFile.write("Chuck Norris can win a game of Connect 4 in only 3 moves.", "#{dir2b}/file2b.txt")
27
+ end
28
+
29
+ it "should determine whether a substring is in any of the files in a directory" do
30
+ expect(StringInPath.present("divide by zero", "#{dir1}")).to eq(true)
31
+ expect(StringInPath.present("divide by zero", "#{dir1a}")).to eq(false)
32
+ expect(StringInPath.present("divide by zero", "#{dir1b}")).to eq(false)
33
+ expect(StringInPath.present("divide by zero", "#{dir2}")).to eq(false)
34
+ expect(StringInPath.present("divide by zero", "#{dir2a}")).to eq(false)
35
+ expect(StringInPath.present("divide by zero", "#{dir2b}")).to eq(false)
36
+
37
+ expect(StringInPath.present("Grumpy Cat", "#{dir1}")).to eq(true)
38
+ expect(StringInPath.present("Grumpy Cat", "#{dir1a}")).to eq(true)
39
+ expect(StringInPath.present("Grumpy Cat", "#{dir1b}")).to eq(false)
40
+ expect(StringInPath.present("Grumpy Cat", "#{dir2}")).to eq(false)
41
+ expect(StringInPath.present("Grumpy Cat", "#{dir2a}")).to eq(false)
42
+ expect(StringInPath.present("Grumpy Cat", "#{dir2b}")).to eq(false)
43
+
44
+ expect(StringInPath.present("counted to infinity", "#{dir1}")).to eq(true)
45
+ expect(StringInPath.present("counted to infinity", "#{dir1a}")).to eq(false)
46
+ expect(StringInPath.present("counted to infinity", "#{dir1b}")).to eq(true)
47
+ expect(StringInPath.present("counted to infinity", "#{dir2}")).to eq(false)
48
+ expect(StringInPath.present("counted to infinity", "#{dir2a}")).to eq(false)
49
+ expect(StringInPath.present("counted to infinity", "#{dir2b}")).to eq(false)
50
+
51
+ expect(StringInPath.present("ice cubes", "#{dir1}")).to eq(false)
52
+ expect(StringInPath.present("ice cubes", "#{dir1a}")).to eq(false)
53
+ expect(StringInPath.present("ice cubes", "#{dir1b}")).to eq(false)
54
+ expect(StringInPath.present("ice cubes", "#{dir2}")).to eq(true)
55
+ expect(StringInPath.present("ice cubes", "#{dir2a}")).to eq(false)
56
+ expect(StringInPath.present("ice cubes", "#{dir2b}")).to eq(false)
57
+
58
+ expect(StringInPath.present("Waldo", "#{dir1}")).to eq(false)
59
+ expect(StringInPath.present("Waldo", "#{dir1a}")).to eq(false)
60
+ expect(StringInPath.present("Waldo", "#{dir1b}")).to eq(false)
61
+ expect(StringInPath.present("Waldo", "#{dir2}")).to eq(true)
62
+ expect(StringInPath.present("Waldo", "#{dir2a}")).to eq(true)
63
+ expect(StringInPath.present("Waldo", "#{dir2b}")).to eq(false)
64
+
65
+ expect(StringInPath.present("Connect 4", "#{dir1}")).to eq(false)
66
+ expect(StringInPath.present("Connect 4", "#{dir1a}")).to eq(false)
67
+ expect(StringInPath.present("Connect 4", "#{dir1b}")).to eq(false)
68
+ expect(StringInPath.present("Connect 4", "#{dir2}")).to eq(true)
69
+ expect(StringInPath.present("Connect 4", "#{dir2a}")).to eq(false)
70
+ expect(StringInPath.present("Connect 4", "#{dir2b}")).to eq(true)
71
+ end
72
+
73
+ it "should replace a substring in every file in a directory with a different substring" do
74
+ StringInPath.replace("Chuck Norris", "Shelby Marx", "#{dir1}")
75
+ StringInPath.replace("Chuck Norris", "Shelby Marx", "#{dir2}")
76
+ end
77
+
78
+ it "should verify that the process of replacing every substring in every file in a directory succeeded" do
79
+ expect(StringInFile.read("#{dir1}/file1.txt")).to eq("Shelby Marx can divide by zero.")
80
+ expect(StringInFile.read("#{dir1a}/file1a.txt")).to eq("Shelby Marx can make Grumpy Cat happy.")
81
+ expect(StringInFile.read("#{dir1b}/file1b.txt")).to eq("Shelby Marx counted to infinity - twice.")
82
+ expect(StringInFile.read("#{dir2}/file2.txt")).to eq("Shelby Marx can start a fire by rubbing two ice cubes together.")
83
+ expect(StringInFile.read("#{dir2a}/file2a.txt")).to eq("Waldo is hiding from Shelby Marx.")
84
+ expect(StringInFile.read("#{dir2b}/file2b.txt")).to eq("Shelby Marx can win a game of Connect 4 in only 3 moves.")
85
+ system("rm -r #{dir_parent}")
86
+ end
87
+
88
+ end
@@ -0,0 +1 @@
1
+ require 'string_in_path'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'string_in_path/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "string_in_path"
8
+ spec.version = StringInPath::VERSION
9
+ spec.authors = ["Jason Hsu"]
10
+ spec.email = ["Rubyist"]
11
+ spec.summary = %q{Find out if a substring is present in any files within a directory. You can even replace it with another substring.}
12
+ spec.description = %q{Find out if a substring is present in any files within a directory. You can even replace it with another substring.}
13
+ spec.homepage = "https://github.com/jhsu802701/string_in_path"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "string_in_file"
25
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_in_path
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Hsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: string_in_file
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Find out if a substring is present in any files within a directory. You
70
+ can even replace it with another substring.
71
+ email:
72
+ - Rubyist
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/string_in_path.rb
83
+ - lib/string_in_path/version.rb
84
+ - spec/lib/string_in_path_spec.rb
85
+ - spec/spec_helper.rb
86
+ - string_in_path.gemspec
87
+ homepage: https://github.com/jhsu802701/string_in_path
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Find out if a substring is present in any files within a directory. You
111
+ can even replace it with another substring.
112
+ test_files:
113
+ - spec/lib/string_in_path_spec.rb
114
+ - spec/spec_helper.rb