mt_line_eraser 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mt_line_eraser.rb +21 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0af945ccd7b5483604b3ad540e3232cd583d3dd096bdb15fe7a26fcc72a38d
|
4
|
+
data.tar.gz: 376b197a78ccf94b4890794025d06b7b78bab11b28959f92518963572a127d33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a5f9a65ae9fb1d4d419945f8c8f3d44696711c901f905d11ff007dd4f21462d6ba2b06218a950ebd042616060504e713271001e9cc7fcd375b678932cdee161
|
7
|
+
data.tar.gz: 44b439f11e1d3b0dbcb7ea766f26e9fa2cb22ae26f8ce4f5891dbfc0f805f1d231e6b9f9d162a5c5fa02f802cc54ed616c3e3e252bf5b904dcb03861ee5a01f9
|
data/lib/mt_line_eraser.rb
CHANGED
@@ -1,15 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class MtLineEraser
|
2
4
|
class << self
|
3
|
-
def erase_in(
|
4
|
-
return
|
5
|
-
|
6
|
-
|
5
|
+
def erase_in(file_or_dir_path)
|
6
|
+
return 'Invalid File path' unless File.exist?(file_or_dir_path)
|
7
|
+
|
8
|
+
files_to_be_processed = if File.file?(file_or_dir_path)
|
9
|
+
[file_or_dir_path]
|
10
|
+
else
|
11
|
+
Dir["#{file_or_dir_path}/**/*.*"]
|
12
|
+
end
|
13
|
+
files_to_be_processed.each do |_file|
|
14
|
+
erase_empty_lines_in_file(_file)
|
15
|
+
p "Erased all the empty lines from #{_file}"
|
16
|
+
end
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def erase_empty_lines_in_file(file_path)
|
21
|
+
original_file = File.open(file_path, 'r')
|
22
|
+
clone_file = File.open("#{file_path}.clone", 'w')
|
7
23
|
original_file.readlines.each do |line|
|
8
24
|
clone_file.write(line) if line.gsub(/^[\s|\n]*/, '') != ''
|
9
25
|
end
|
10
|
-
[original_file, clone_file].map
|
26
|
+
[original_file, clone_file].map(&:close)
|
11
27
|
File.rename(clone_file, original_file)
|
12
|
-
"Erased all the empty lines from #{file_name_with_path}"
|
13
28
|
end
|
14
29
|
end
|
15
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mt_line_eraser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Subash R
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Erase the empty lines in a specified file
|
14
14
|
email:
|
@@ -22,6 +22,7 @@ homepage: https://github.com/subashravichandran/mt_line_eraser
|
|
22
22
|
licenses:
|
23
23
|
- MIT
|
24
24
|
metadata:
|
25
|
+
source_code_uri: https://github.com/subashravichandran/mt_line_eraser/blob/main/lib/mt_line_eraser.rb
|
25
26
|
homepage_uri: https://github.com/subashravichandran/mt_line_eraser
|
26
27
|
post_install_message:
|
27
28
|
rdoc_options: []
|