insert_from_file 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/README.md +6 -6
- data/lib/insert_from_file.rb +68 -8
- data/lib/insert_from_file/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d5710541f1f3d0e382d0956150a312c40490f4
|
4
|
+
data.tar.gz: e9045dc7b6601cfd30b1d96677982448c83478d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f19c042cacb3c59f541d35186b1395e2b39864519c83f56850a3d87460efd8c4acb9c4d3b5dedf8378fe7d2d7551df526235a8c70171a770c078b431e27f86
|
7
|
+
data.tar.gz: b41ad115d96c3922a0b0c7270f34d2cbcd32e93e99c005e4504295d7e64adf69c1983111a3b48202f0fdf2d434868f4014d80663feb8299f29e1e4080d0f9591
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Exclude:
|
3
|
+
- lib/insert_from_file.rb
|
4
|
+
|
1
5
|
Metrics/BlockLength:
|
2
6
|
Exclude:
|
3
7
|
- insert_from_file.gemspec
|
@@ -6,3 +10,7 @@ Metrics/BlockLength:
|
|
6
10
|
Metrics/LineLength:
|
7
11
|
Exclude:
|
8
12
|
- insert_from_file.gemspec
|
13
|
+
|
14
|
+
Metrics/ModuleLength:
|
15
|
+
Exclude:
|
16
|
+
- lib/insert_from_file.rb
|
data/README.md
CHANGED
@@ -17,12 +17,12 @@ The InsertFromFile gem is for inserting the contents of one file into another fi
|
|
17
17
|
* tmp/file1.txt:
|
18
18
|
```
|
19
19
|
one two three
|
20
|
-
four five six
|
21
20
|
ten eleven twelve
|
22
21
|
thirteen fourteen fifteen
|
23
22
|
```
|
24
23
|
* tmp/file2.txt:
|
25
24
|
```
|
25
|
+
four five six
|
26
26
|
seven eight nine
|
27
27
|
```
|
28
28
|
* Adding the contents of tmp/file2.txt before the line in tmp/file1.txt containing 'ten':
|
@@ -35,12 +35,12 @@ InsertFromFile.add_before('tmp/file2.txt', 'tmp/file1.txt', 'ten')
|
|
35
35
|
```
|
36
36
|
one two three
|
37
37
|
four five six
|
38
|
-
ten eleven twelve
|
39
38
|
thirteen fourteen fifteen
|
40
39
|
```
|
41
40
|
* tmp/file4.txt:
|
42
41
|
```
|
43
42
|
seven eight nine
|
43
|
+
ten eleven twelve
|
44
44
|
```
|
45
45
|
* Adding the contents of tmp/file4.txt after the line in tmp/file3.txt containing 'six':
|
46
46
|
```
|
@@ -53,12 +53,12 @@ InsertFromFile.add_after('tmp/file4.txt', 'tmp/file3.txt', 'six')
|
|
53
53
|
one two three
|
54
54
|
four five six
|
55
55
|
sixteen seventeen eighteen
|
56
|
-
ten eleven twelve
|
57
56
|
thirteen fourteen fifteen
|
58
57
|
```
|
59
58
|
* tmp/file6.txt:
|
60
59
|
```
|
61
60
|
seven eight nine
|
61
|
+
ten eleven twelve
|
62
62
|
```
|
63
63
|
* Adding the contents of tmp/file6.txt into tmp/file5.txt in place of the line containing 'sixteen':
|
64
64
|
```
|
@@ -71,12 +71,12 @@ InsertFromFile.replace('tmp/file6.txt', 'tmp/file5.txt', 'sixteen')
|
|
71
71
|
one two three
|
72
72
|
four five six
|
73
73
|
sixteen seventeen eighteen
|
74
|
-
ten eleven twelve
|
75
74
|
thirteen fourteen fifteen
|
76
75
|
```
|
77
76
|
* tmp/file12.txt:
|
78
77
|
```
|
79
78
|
seven eight nine
|
79
|
+
ten eleven twelve
|
80
80
|
```
|
81
81
|
* Adding the contents of tmp/file12.txt into tmp/file11.txt and replacing everything after the line containing "five" and before the line containing "eleven":
|
82
82
|
```
|
@@ -86,7 +86,6 @@ InsertFromFile.replace_between('tmp/file12.txt', 'tmp/file11.txt', 'five', 'elev
|
|
86
86
|
### add_beginning
|
87
87
|
* tmp/file13.txt:
|
88
88
|
```
|
89
|
-
four five six
|
90
89
|
seven eight nine
|
91
90
|
ten eleven twelve
|
92
91
|
thirteen fourteen fifteen
|
@@ -94,6 +93,7 @@ thirteen fourteen fifteen
|
|
94
93
|
* tmp/file14.txt:
|
95
94
|
```
|
96
95
|
one two three
|
96
|
+
four five six
|
97
97
|
```
|
98
98
|
* Adding the contents of tmp/file14.txt to the beginning of tmp/file13.txt:
|
99
99
|
```
|
@@ -106,10 +106,10 @@ InsertFromFile.add_beginning('tmp/file14.txt', 'tmp/file13.txt')
|
|
106
106
|
one two three
|
107
107
|
four five six
|
108
108
|
seven eight nine
|
109
|
-
ten eleven twelve
|
110
109
|
```
|
111
110
|
* tmp/file16.txt:
|
112
111
|
```
|
112
|
+
ten eleven twelve
|
113
113
|
thirteen fourteen fifteen
|
114
114
|
```
|
115
115
|
* Adding the contents of temp/file16.txt to the beginning of tmp/file15.txt:
|
data/lib/insert_from_file.rb
CHANGED
@@ -6,23 +6,83 @@ require 'string_in_file'
|
|
6
6
|
#
|
7
7
|
module InsertFromFile
|
8
8
|
def self.add_before(file_source, file_dest, str_dest)
|
9
|
-
|
10
|
-
|
9
|
+
path_old = file_dest
|
10
|
+
path_new = "#{path_old}.new"
|
11
|
+
file_w = open(path_new, 'w')
|
12
|
+
File.readlines(path_old).each do |line|
|
13
|
+
if line.include? str_dest
|
14
|
+
File.readlines(file_source).each do |line_s|
|
15
|
+
file_w.write(line_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
file_w.write(line)
|
19
|
+
end
|
20
|
+
file_w.close
|
21
|
+
system("rm #{path_old}")
|
22
|
+
system("mv #{path_new} #{path_old}")
|
11
23
|
end
|
12
24
|
|
13
25
|
def self.add_after(file_source, file_dest, str_dest)
|
14
|
-
|
15
|
-
|
26
|
+
path_old = file_dest
|
27
|
+
path_new = "#{path_old}.new"
|
28
|
+
file_w = open(path_new, 'w')
|
29
|
+
File.readlines(path_old).each do |line|
|
30
|
+
file_w.write(line)
|
31
|
+
# rubocop:disable Style/Next
|
32
|
+
if line.include? str_dest
|
33
|
+
File.readlines(file_source).each do |line_s|
|
34
|
+
file_w.write(line_s)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# rubocop:enable Style/Next
|
38
|
+
end
|
39
|
+
file_w.close
|
40
|
+
system("rm #{path_old}")
|
41
|
+
system("mv #{path_new} #{path_old}")
|
16
42
|
end
|
17
43
|
|
18
44
|
def self.replace(file_source, file_dest, str_dest)
|
19
|
-
|
20
|
-
|
45
|
+
path_old = file_dest
|
46
|
+
path_new = "#{path_old}.new"
|
47
|
+
file_w = open(path_new, 'w')
|
48
|
+
File.readlines(path_old).each do |line|
|
49
|
+
if line.include? str_dest
|
50
|
+
File.readlines(file_source).each do |line_s|
|
51
|
+
file_w.write(line_s)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
file_w.write(line)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
file_w.close
|
58
|
+
system("rm #{path_old}")
|
59
|
+
system("mv #{path_new} #{path_old}")
|
21
60
|
end
|
22
61
|
|
23
62
|
def self.replace_between(file_source, file_dest, str1, str2)
|
24
|
-
|
25
|
-
|
63
|
+
path_old = file_dest
|
64
|
+
path_new = "#{path_old}.new"
|
65
|
+
file_w = open(path_new, 'w')
|
66
|
+
is_before = true
|
67
|
+
is_after = false
|
68
|
+
File.readlines(path_old).each do |line|
|
69
|
+
if is_before == true # Beginning
|
70
|
+
file_w.write(line)
|
71
|
+
if line.include? str1
|
72
|
+
File.readlines(file_source).each do |line_s|
|
73
|
+
file_w.write(line_s)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
elsif is_after == true # End
|
77
|
+
file_w.write(line)
|
78
|
+
elsif line.include? str2 # Middle
|
79
|
+
file_w.write(line)
|
80
|
+
is_after = true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
file_w.close
|
84
|
+
system("rm #{path_old}")
|
85
|
+
system("mv #{path_new} #{path_old}")
|
26
86
|
end
|
27
87
|
|
28
88
|
def self.add_beginning(file_source, file_dest)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insert_from_file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Hsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|