line_containing 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2994d50472bfc4d1c1c36c12af9fe81bee82a32
4
- data.tar.gz: cacd4acf257d8da52eaeb5b063f7e11bc1b71442
3
+ metadata.gz: fc22ec2ca3168f956e817aebe27805c3b1e11e96
4
+ data.tar.gz: 6c64a43c546870b13028a7fb778c930edf526b47
5
5
  SHA512:
6
- metadata.gz: 73d21c3ebe735f1ca402dd2268e20c1f72f2e5452e2c34af6403d638a294627db9470c62b97ddb031250726257c0eca7ca53655b6c536b570a91d4a97642387d
7
- data.tar.gz: a9e29adbe32fc1fcaff56772255a26971e22272351ef2ac158be11dcee389e101fde9a9413dbb44dca6d7a65be06293279c787fdc6eea3acd2f120f3952ce4c6
6
+ metadata.gz: 93a95d57745c77ad59151eb6bb05c361b3c8188f9ab7956ebf26aeae7913c56d436bca04bfd9a2a448472453abbab648b79f036385c62b7212728c6cea4de70e
7
+ data.tar.gz: 1cfb56a051af03a39bb3ea007cad765e8410ac49b2058f9550dc1ff329289d02c3f5466428378706c312764ea1d56fb6c816cc406070bcffb80142a2ca70d119
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /tmp
11
11
  /tmp*
12
12
  .DS_Store
13
+ /log/*
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Exclude:
3
+ - tmp/vulnerabilities/lib/*
4
+ - tmp/vulnerabilities/spec/*
5
+ - tmp/vulnerabilities/Rakefile
6
+
7
+ Metrics/LineLength:
8
+ Exclude:
9
+ - line_containing.gemspec
10
+
11
+ Metrics/MethodLength:
12
+ Exclude:
13
+ - lib/line_containing.rb
@@ -1,3 +1,5 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.2.0
4
+ - 2.3.1
5
+ before_install: gem install bundler
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # LineContaining
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/line_containing.svg)](https://badge.fury.io/rb/line_containing)
4
+ [![Build Status](https://travis-ci.org/jhsu802701/line_containing.svg?branch=version_0_0_1)](https://travis-ci.org/jhsu802701/line_containing)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/jhsu802701/line_containing.svg)](https://gemnasium.com/github.com/jhsu802701/line_containing)
6
+ [![Code Climate](https://codeclimate.com/github/jhsu802701/line_containing/badges/gpa.svg)](https://codeclimate.com/github/jhsu802701/line_containing)
7
+ [![Test Coverage](https://codeclimate.com/github/jhsu802701/line_containing/badges/coverage.svg)](https://codeclimate.com/github/jhsu802701/line_containing/coverage)
8
+
3
9
  ## What This Gem Does
4
10
 
5
11
  The LineContaing gem is changing the contents of a file based on the content in a line. Some examples:
@@ -79,6 +85,34 @@ ten eleven twelve
79
85
  thirteen fourteen fifteen
80
86
  ```
81
87
 
88
+ * Look for lines containing specific content, and delete everything in between.
89
+ ```
90
+ one two three
91
+ a b c
92
+ d e f
93
+ g h i
94
+ four five six
95
+ ```
96
+ Delete the lines between "two" and "five".
97
+ ```
98
+ one two three
99
+ four five six
100
+ ```
101
+
102
+ * Look for lines containing specific content, delete them, and delete everything in between.
103
+ ```
104
+ one two three
105
+ a b c
106
+ d e f
107
+ g h i
108
+ four five six
109
+ ```
110
+ Delete the lines containing "two" and "five" plus everything in between.
111
+ ```
112
+ one two three
113
+ four five six
114
+ ```
115
+
82
116
  ## Installation
83
117
 
84
118
  Add this line to your application's Gemfile:
@@ -122,6 +156,18 @@ EXAMPLE: In the file "file4.txt", look for the line containing "seventeen", and
122
156
  LineContaining.delete("seventeen", "file4.txt")
123
157
  ```
124
158
 
159
+ #### Look for lines containing specific content, and delete everything in between.
160
+ EXAMPLE: In the file "file7.txt", look for the line containing "one" and the line containing "six", and delete everything in between.
161
+ ```
162
+ LineContaining.delete_between('one', 'six', 'file7.txt')
163
+ ```
164
+
165
+ #### Look for lines containing specific content. Delete these lines and everything in between.
166
+ EXAMPLE: In the file "file8.txt", look for the line containing "a b" and the line containing "h i". Delete these lines and everything in between.
167
+ ```
168
+ LineContaining.delete_between_plus('a b', 'h i', 'file8.txt')
169
+ ```
170
+
125
171
  ## Development
126
172
 
127
173
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
- task :default => :spec
7
- task :test => :spec
6
+ task default: :spec
7
+ task test: :spec
8
8
 
9
9
  # TEST GEM: Enter "rake".
10
10
  # INSTALL GEM: Enter "rake install".
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "line_containing"
3
+ require 'bundler/setup'
4
+ require 'line_containing'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ DIR_PARENT="${PWD%/*}"
4
+ DIR_TMP="$DIR_PARENT/tmp"
5
+ mkdir -p log
6
+ rm -rf tmp
7
+
8
+ echo '--------------'
9
+ echo 'bundle install'
10
+ bin/setup >/dev/null
11
+
12
+ echo
13
+ echo '----------'
14
+ echo 'rubocop -D'
15
+ rubocop -D
16
+
17
+ echo
18
+ echo '-----------'
19
+ echo 'sandi_meter'
20
+ sandi_meter
21
+
22
+ echo
23
+ echo '------------'
24
+ echo 'bundle-audit'
25
+ bundle-audit
26
+
27
+ echo '----------------------------------------------'
28
+ echo 'gemsurance --output log/gemsurance_report.html'
29
+ gemsurance --output log/gemsurance_report.html
30
+ echo 'Gemsurance Report: log/gemsurance_report.html'
31
+
32
+ echo '------------------------------------------------------------------------'
33
+ echo 'bundle viz --file=log/diagram-gems --format=svg --requirements --version'
34
+ bundle viz --file=log/diagram-gems --format=svg --requirements --version
35
+ echo 'Gem dependency diagram: log/diagram-gems.svg'
@@ -1,24 +1,21 @@
1
- require "line_containing/version"
1
+ require 'line_containing/version'
2
2
 
3
+ #
3
4
  module LineContaining
4
5
  def self.add_before(str_orig, str_add, path)
5
- system("pwd")
6
+ system('pwd')
6
7
  path_old = path
7
8
  path_new = "#{path_old}.new"
8
9
  file_w = open(path_new, 'w')
9
10
  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
11
+ file_w.write("#{str_add}\n") if line.include? str_orig
12
+ file_w.write(line)
16
13
  end
17
14
  file_w.close
18
15
  system("rm #{path_old}")
19
16
  system("mv #{path_new} #{path_old}")
20
17
  end
21
-
18
+
22
19
  def self.add_after(str_orig, str_add, path)
23
20
  path_old = path
24
21
  path_new = "#{path_old}.new"
@@ -36,7 +33,7 @@ module LineContaining
36
33
  system("rm #{path_old}")
37
34
  system("mv #{path_new} #{path_old}")
38
35
  end
39
-
36
+
40
37
  def self.replace(str_orig, str_new, path)
41
38
  path_old = path
42
39
  path_new = "#{path_old}.new"
@@ -52,7 +49,7 @@ module LineContaining
52
49
  system("rm #{path_old}")
53
50
  system("mv #{path_new} #{path_old}")
54
51
  end
55
-
52
+
56
53
  def self.delete(str_orig, path)
57
54
  path_old = path
58
55
  path_new = "#{path_old}.new"
@@ -68,4 +65,31 @@ module LineContaining
68
65
  system("rm #{path_old}")
69
66
  system("mv #{path_new} #{path_old}")
70
67
  end
68
+
69
+ def self.delete_between(str1, str2, path)
70
+ path_old = path
71
+ path_new = "#{path_old}.new"
72
+ file_w = open(path_new, 'w')
73
+ to_delete = false
74
+ File.readlines(path_old).each do |line|
75
+ if line.include? str1
76
+ file_w.write(line)
77
+ to_delete = true
78
+ elsif line.include? str2
79
+ file_w.write(line)
80
+ to_delete = false
81
+ elsif to_delete == false
82
+ file_w.write(line)
83
+ end
84
+ end
85
+ file_w.close
86
+ system("rm #{path_old}")
87
+ system("mv #{path_new} #{path_old}")
88
+ end
89
+
90
+ def self.delete_between_plus(str1, str2, path)
91
+ delete_between(str1, str2, path)
92
+ delete(str1, path)
93
+ delete(str2, path)
94
+ end
71
95
  end
@@ -1,3 +1,3 @@
1
1
  module LineContaining
2
- VERSION = "0.0.0"
2
+ VERSION = '0.1.0'.freeze
3
3
  end
@@ -4,22 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'line_containing/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "line_containing"
7
+ spec.name = 'line_containing'
8
8
  spec.version = LineContaining::VERSION
9
- spec.authors = ["Jason Hsu"]
10
- spec.email = ["rubyist@jasonhsu.com"]
9
+ spec.authors = ['Jason Hsu']
10
+ spec.email = ['rubyist@jasonhsu.com']
11
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"
12
+ spec.summary = '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 = '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
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.8"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency 'bundler', '~> 1.8'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
+
26
+ spec.add_development_dependency 'simplecov'
27
+
28
+ spec.add_development_dependency 'ruby-graphviz'
29
+
30
+ spec.add_development_dependency 'gemsurance'
31
+
32
+ spec.add_development_dependency 'bundler-audit'
33
+
34
+ spec.add_development_dependency 'sandi_meter'
35
+
36
+ spec.add_development_dependency 'rubocop'
37
+
38
+ spec.add_development_dependency 'codeclimate-test-reporter'
25
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line_containing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Hsu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,104 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
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
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-graphviz
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gemsurance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler-audit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sandi_meter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: codeclimate-test-reporter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
55
153
  description: Remove or replace a line from a file based on its content. Look for
56
154
  a line with certain content, and add another line before or after it.
57
155
  email:
@@ -62,6 +160,7 @@ extra_rdoc_files: []
62
160
  files:
63
161
  - ".gitignore"
64
162
  - ".rspec"
163
+ - ".rubocop.yml"
65
164
  - ".travis.yml"
66
165
  - CODE_OF_CONDUCT.md
67
166
  - Gemfile
@@ -70,6 +169,7 @@ files:
70
169
  - Rakefile
71
170
  - bin/console
72
171
  - bin/setup
172
+ - code_test.sh
73
173
  - gem_console.sh
74
174
  - gem_install.sh
75
175
  - gem_test.sh
@@ -96,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
196
  version: '0'
97
197
  requirements: []
98
198
  rubyforge_project:
99
- rubygems_version: 2.4.6
199
+ rubygems_version: 2.5.1
100
200
  signing_key:
101
201
  specification_version: 4
102
202
  summary: Remove or replace a line from a file based on its content. Look for a line