mt_line_eraser 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mt_line_eraser.rb +14 -5
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4874133fd9a13bd0dfa27e498d46fca0acc4187ca7d2f4e739816b753713108b
4
- data.tar.gz: e6a628956de7b848d0c5723977fc5ae529aaeb6515d60fe3bb7854b0bb92e8cf
3
+ metadata.gz: 33b4fb6b9757c1025faa5e7ec5bf8f1c348cb34b66385aa571acf2c2a0314790
4
+ data.tar.gz: da67dbd17f47c644375933b530fae6a26ef0d3fb0e8db602028c514b3aef5bda
5
5
  SHA512:
6
- metadata.gz: 2ee92d59f58276c81e434be4ec41b6abb7e0793b4de0d3376e3359470b70d642816dab6d1e38f53a6b9b8fbd5c637037d02cf5b0d56207a7ae1745cf5cb0ddec
7
- data.tar.gz: 61e20e0aa181d8151b5dff5b86356dbe4afea1e87d8ea176d8db7b166544213d1b44e57e4457ee57247559f3378c9c10c92d9eb899aaa01a5ffa693fdffe49a0
6
+ metadata.gz: 5ae32b032cb0b3150fd194d1c2fda2e9b73141879f9e484478928597fc4e079fb2ab69fba2ca142189acfce800d42f2b7d7e6d46223ae070efabdfe5c37d791c
7
+ data.tar.gz: 3f497309990760ef4cf78c42144b96bbeb341364abc7e8a447196662218ca672c763188baeb40613902ac5008049249ef4d3734bb1a663925a654d2a16aaeedb
@@ -1,15 +1,24 @@
1
1
  class MtLineEraser
2
2
  class << self
3
- def erase_in(file_name_with_path)
4
- return "Invalid File path" unless File.exists?(file_name_with_path)
5
- original_file = File.open(file_name_with_path, 'r')
6
- clone_file = File.open(file_name_with_path + '.clone', 'w')
3
+ def erase_in(file_or_dir_path)
4
+ return "Invalid File path" unless File.exists?(file_or_dir_path)
5
+ files_to_be_processed = File.file?(file_or_dir_path) ? file_or_dir_path
6
+ : Dir["#{file_or_dir_path}/**/*.*"]
7
+ files_to_be_processed.each do |_file|
8
+ erase_empty_lines_in_file(_file)
9
+ p "Erased all the empty lines from #{_file}"
10
+ end
11
+ return nil
12
+ end
13
+
14
+ def erase_empty_lines_in_file(file_path)
15
+ original_file = File.open(file_path, 'r')
16
+ clone_file = File.open(file_path + '.clone', 'w')
7
17
  original_file.readlines.each do |line|
8
18
  clone_file.write(line) if line.gsub(/^[\s|\n]*/, '') != ''
9
19
  end
10
20
  [original_file, clone_file].map{|_file| _file.close}
11
21
  File.rename(clone_file, original_file)
12
- "Erased all the empty lines from #{file_name_with_path}"
13
22
  end
14
23
  end
15
24
  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.3
4
+ version: 0.0.4
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 00:00:00.000000000 Z
11
+ date: 2022-12-13 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: []