line_containing 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gem_console.sh +6 -0
- data/gem_install.sh +6 -0
- data/gem_test.sh +6 -0
- data/lib/line_containing/version.rb +3 -0
- data/lib/line_containing.rb +71 -0
- data/line_containing.gemspec +25 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2994d50472bfc4d1c1c36c12af9fe81bee82a32
|
4
|
+
data.tar.gz: cacd4acf257d8da52eaeb5b063f7e11bc1b71442
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73d21c3ebe735f1ca402dd2268e20c1f72f2e5452e2c34af6403d638a294627db9470c62b97ddb031250726257c0eca7ca53655b6c536b570a91d4a97642387d
|
7
|
+
data.tar.gz: a9e29adbe32fc1fcaff56772255a26971e22272351ef2ac158be11dcee389e101fde9a9413dbb44dca6d7a65be06293279c787fdc6eea3acd2f120f3952ce4c6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jason Hsu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# LineContaining
|
2
|
+
|
3
|
+
## What This Gem Does
|
4
|
+
|
5
|
+
The LineContaing gem is changing the contents of a file based on the content in a line. Some examples:
|
6
|
+
|
7
|
+
* Look for a line containing specific content, and add a new line before it.
|
8
|
+
```
|
9
|
+
one two three
|
10
|
+
four five six
|
11
|
+
ten eleven twelve
|
12
|
+
thirteen fourteen fifteen
|
13
|
+
```
|
14
|
+
Add the line "seven eight nine" before the line containing "ten".
|
15
|
+
```
|
16
|
+
one two three
|
17
|
+
four five six
|
18
|
+
seven eight nine
|
19
|
+
ten eleven twelve
|
20
|
+
thirteen fourteen fifteen
|
21
|
+
```
|
22
|
+
|
23
|
+
* Look for a line containing specific content, and add a new line after it.
|
24
|
+
|
25
|
+
```
|
26
|
+
one two three
|
27
|
+
four five six
|
28
|
+
ten eleven twelve
|
29
|
+
thirteen fourteen fifteen
|
30
|
+
```
|
31
|
+
Add the line "seven eight nine" after the line containing "six"
|
32
|
+
```
|
33
|
+
one two three
|
34
|
+
four five six
|
35
|
+
seven eight nine
|
36
|
+
ten eleven twelve
|
37
|
+
thirteen fourteen fifteen
|
38
|
+
```
|
39
|
+
|
40
|
+
* Look for a line containing specific content, and add a new line in place of it.
|
41
|
+
|
42
|
+
```
|
43
|
+
one two three
|
44
|
+
four five six
|
45
|
+
sixteen seventeen eighteen
|
46
|
+
ten eleven twelve
|
47
|
+
thirteen fourteen fifteen
|
48
|
+
```
|
49
|
+
|
50
|
+
Add the line "seven eight nine" in place of the line containing "seventeen".
|
51
|
+
|
52
|
+
```
|
53
|
+
one two three
|
54
|
+
four five six
|
55
|
+
seven eight nine
|
56
|
+
ten eleven twelve
|
57
|
+
thirteen fourteen fifteen
|
58
|
+
```
|
59
|
+
|
60
|
+
* Look for a line containing specific content, and delete this line.
|
61
|
+
|
62
|
+
```
|
63
|
+
one two three
|
64
|
+
four five six
|
65
|
+
seven eight nine
|
66
|
+
sixteen seventeen eighteen
|
67
|
+
ten eleven twelve
|
68
|
+
thirteen fourteen fifteen
|
69
|
+
```
|
70
|
+
|
71
|
+
Delete the line containing "seventeen".
|
72
|
+
|
73
|
+
|
74
|
+
```
|
75
|
+
one two three
|
76
|
+
four five six
|
77
|
+
seven eight nine
|
78
|
+
ten eleven twelve
|
79
|
+
thirteen fourteen fifteen
|
80
|
+
```
|
81
|
+
|
82
|
+
## Installation
|
83
|
+
|
84
|
+
Add this line to your application's Gemfile:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
gem 'line_containing'
|
88
|
+
```
|
89
|
+
|
90
|
+
And then execute:
|
91
|
+
|
92
|
+
$ bundle
|
93
|
+
|
94
|
+
Or install it yourself as:
|
95
|
+
|
96
|
+
$ gem install line_containing
|
97
|
+
|
98
|
+
## Usage
|
99
|
+
|
100
|
+
#### Look for a line containing specific content, and add a new line before it.
|
101
|
+
EXAMPLE: In the file "file1.txt", look for the line containing "ten", and add the line "seven eight nine" before it.
|
102
|
+
|
103
|
+
```
|
104
|
+
LineContaining.add_before("ten", "seven eight nine", "file1.txt")
|
105
|
+
```
|
106
|
+
|
107
|
+
#### Look for a line containing specific content, and add a new line after it.
|
108
|
+
EXAMPLE: In the file "file2.txt", look for the line containing "six", and add the line "seven eight nine" after it.
|
109
|
+
```
|
110
|
+
LineContaining.add_after("six", "seven eight nine", "file2.txt")
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Look for a line containing specific content, and add a new line in place of it.
|
114
|
+
EXAMPLE: In the file "file3.txt", look for the line containing "seventeen", and add the line "seven eight nine" in place of it.
|
115
|
+
```
|
116
|
+
LineContaining.replace("seventeen", "seven eight nine", "file3.txt")
|
117
|
+
```
|
118
|
+
|
119
|
+
#### Look for a line containing specific content, and delete this line.
|
120
|
+
EXAMPLE: In the file "file4.txt", look for the line containing "seventeen", and delete it.
|
121
|
+
```
|
122
|
+
LineContaining.delete("seventeen", "file4.txt")
|
123
|
+
```
|
124
|
+
|
125
|
+
## Development
|
126
|
+
|
127
|
+
|
128
|
+
### Testing this gem
|
129
|
+
|
130
|
+
Enter `sh gem_test.sh`.
|
131
|
+
|
132
|
+
### Running this gem in irb
|
133
|
+
|
134
|
+
Enter `sh gem_console.sh`.
|
135
|
+
|
136
|
+
### Installing this gem
|
137
|
+
|
138
|
+
Enter `sh gem_install.sh`.
|
139
|
+
|
140
|
+
## Contributing
|
141
|
+
|
142
|
+
1. Fork it ( https://github.com/[my-github-username]/line_containing/fork )
|
143
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
144
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
145
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
146
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "line_containing"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/gem_console.sh
ADDED
data/gem_install.sh
ADDED
data/gem_test.sh
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "line_containing/version"
|
2
|
+
|
3
|
+
module LineContaining
|
4
|
+
def self.add_before(str_orig, str_add, path)
|
5
|
+
system("pwd")
|
6
|
+
path_old = path
|
7
|
+
path_new = "#{path_old}.new"
|
8
|
+
file_w = open(path_new, 'w')
|
9
|
+
File.readlines(path_old).each do |line|
|
10
|
+
if line.include? str_orig
|
11
|
+
file_w.write("#{str_add}\n")
|
12
|
+
file_w.write(line)
|
13
|
+
else
|
14
|
+
file_w.write(line)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
file_w.close
|
18
|
+
system("rm #{path_old}")
|
19
|
+
system("mv #{path_new} #{path_old}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.add_after(str_orig, str_add, path)
|
23
|
+
path_old = path
|
24
|
+
path_new = "#{path_old}.new"
|
25
|
+
file_w = open(path_new, 'w')
|
26
|
+
File.readlines(path_old).each do |line|
|
27
|
+
if line.include? str_orig
|
28
|
+
file_w.write(line)
|
29
|
+
file_w.write("\n") if line[-1] != "\n"
|
30
|
+
file_w.write("#{str_add}\n")
|
31
|
+
else
|
32
|
+
file_w.write(line)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
file_w.close
|
36
|
+
system("rm #{path_old}")
|
37
|
+
system("mv #{path_new} #{path_old}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.replace(str_orig, str_new, path)
|
41
|
+
path_old = path
|
42
|
+
path_new = "#{path_old}.new"
|
43
|
+
file_w = open(path_new, 'w')
|
44
|
+
File.readlines(path_old).each do |line|
|
45
|
+
if line.include? str_orig
|
46
|
+
file_w.write("#{str_new}\n")
|
47
|
+
else
|
48
|
+
file_w.write(line)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
file_w.close
|
52
|
+
system("rm #{path_old}")
|
53
|
+
system("mv #{path_new} #{path_old}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.delete(str_orig, path)
|
57
|
+
path_old = path
|
58
|
+
path_new = "#{path_old}.new"
|
59
|
+
file_w = open(path_new, 'w')
|
60
|
+
File.readlines(path_old).each do |line|
|
61
|
+
if line.include? str_orig
|
62
|
+
# Print NOTHING
|
63
|
+
else
|
64
|
+
file_w.write(line)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
file_w.close
|
68
|
+
system("rm #{path_old}")
|
69
|
+
system("mv #{path_new} #{path_old}")
|
70
|
+
end
|
71
|
+
end
|
@@ -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 'line_containing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "line_containing"
|
8
|
+
spec.version = LineContaining::VERSION
|
9
|
+
spec.authors = ["Jason Hsu"]
|
10
|
+
spec.email = ["rubyist@jasonhsu.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Remove or replace a line from a file based on its content. Look for a line with certain content, and add another line before or after it.}
|
13
|
+
spec.description = %q{Remove or replace a line from a file based on its content. Look for a line with certain content, and add another line before or after it.}
|
14
|
+
spec.homepage = "https://github.com/jhsu802701/line_containing"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: line_containing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Hsu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-19 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: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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
|
+
description: Remove or replace a line from a file based on its content. Look for
|
56
|
+
a line with certain content, and add another line before or after it.
|
57
|
+
email:
|
58
|
+
- rubyist@jasonhsu.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- gem_console.sh
|
74
|
+
- gem_install.sh
|
75
|
+
- gem_test.sh
|
76
|
+
- lib/line_containing.rb
|
77
|
+
- lib/line_containing/version.rb
|
78
|
+
- line_containing.gemspec
|
79
|
+
homepage: https://github.com/jhsu802701/line_containing
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Remove or replace a line from a file based on its content. Look for a line
|
103
|
+
with certain content, and add another line before or after it.
|
104
|
+
test_files: []
|