txt_file_mutator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/CHANGELOG +1 -0
- data/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +18 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/txt_file_mutator.rb +40 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/txt_file_mutator_spec.rb +7 -0
- data/test/test_txt_file_mutator.rb +38 -0
- metadata +79 -0
data/.document
ADDED
data/.gitignore
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A history of changes to the gem...
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= txt_file_mutator
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "txt_file_mutator"
|
8
|
+
gem.summary = %Q{mutate a text file in various ways}
|
9
|
+
gem.description = %Q{includes convenience method to do txt file mutations including simple code refactorings such as commenting a line}
|
10
|
+
gem.email = "kmandrup@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/kristianmandrup/txt_file_mutator"
|
12
|
+
gem.authors = ["Kristian Mandrup"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.files.exclude 'test'
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "txt_file_mutator #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TextFileMutator
|
2
|
+
def self.insert_before(file, line, txt_before)
|
3
|
+
gsub_file file, /(#{Regexp.escape(line)})/mi do |match|
|
4
|
+
"#{txt_before}\n#{match}"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.insert_after(file, line, txt_after)
|
9
|
+
gsub_file file, /(#{Regexp.escape(line)})/mi do |match|
|
10
|
+
"#{match}\n#{txt_after}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.comment_gem_config(file, line)
|
15
|
+
gsub_file file, /^#?(config.gem.+'#{Regexp.escape(line)}'.+)/mi do |match|
|
16
|
+
"# " + "#{match}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.comment_line(file, line)
|
21
|
+
puts "comment line: #{line}"
|
22
|
+
gsub_file file, /^#?(#{Regexp.escape(line)})/mi do |match|
|
23
|
+
puts "match: #{match}"
|
24
|
+
"# " + "#{match}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.remove_line(file, line)
|
29
|
+
gsub_file file, /(#{Regexp.escape(line)})/mi do |match|
|
30
|
+
""
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def self.gsub_file(path, regexp, *args, &block)
|
36
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
37
|
+
File.open(path, 'wb') { |file| file.write(content) }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'txt_file_mutator'
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestFilterExec < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@tfm = TextFileMutator
|
8
|
+
@file = 'DATA.txt'
|
9
|
+
puts @tfm.instance_methods
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
## Nothing really
|
14
|
+
end
|
15
|
+
|
16
|
+
# include method
|
17
|
+
def test_comment_line
|
18
|
+
@tfm.comment_line @file, 'blip'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_comment_gem_config
|
22
|
+
@tfm.comment_gem_config @file, 'hobo'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_remove_line
|
26
|
+
@tfm.remove_line @file, 'remove me'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_insert_before
|
30
|
+
@tfm.insert_before @file, 'before', "BEFORE"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_insert_after
|
34
|
+
@tfm.insert_after @file, 'after', "AFTER"
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: txt_file_mutator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kristian Mandrup
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-13 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: includes convenience method to do txt file mutations including simple code refactorings such as commenting a line
|
26
|
+
email: kmandrup@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- CHANGELOG
|
39
|
+
- LICENSE
|
40
|
+
- README
|
41
|
+
- README.rdoc
|
42
|
+
- Rakefile
|
43
|
+
- VERSION
|
44
|
+
- lib/txt_file_mutator.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- spec/txt_file_mutator_spec.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/kristianmandrup/txt_file_mutator
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: mutate a text file in various ways
|
76
|
+
test_files:
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/txt_file_mutator_spec.rb
|
79
|
+
- test/test_txt_file_mutator.rb
|