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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mt_line_eraser.rb +21 -6
  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: ea0af945ccd7b5483604b3ad540e3232cd583d3dd096bdb15fe7a26fcc72a38d
4
+ data.tar.gz: 376b197a78ccf94b4890794025d06b7b78bab11b28959f92518963572a127d33
5
5
  SHA512:
6
- metadata.gz: 2ee92d59f58276c81e434be4ec41b6abb7e0793b4de0d3376e3359470b70d642816dab6d1e38f53a6b9b8fbd5c637037d02cf5b0d56207a7ae1745cf5cb0ddec
7
- data.tar.gz: 61e20e0aa181d8151b5dff5b86356dbe4afea1e87d8ea176d8db7b166544213d1b44e57e4457ee57247559f3378c9c10c92d9eb899aaa01a5ffa693fdffe49a0
6
+ metadata.gz: 9a5f9a65ae9fb1d4d419945f8c8f3d44696711c901f905d11ff007dd4f21462d6ba2b06218a950ebd042616060504e713271001e9cc7fcd375b678932cdee161
7
+ data.tar.gz: 44b439f11e1d3b0dbcb7ea766f26e9fa2cb22ae26f8ce4f5891dbfc0f805f1d231e6b9f9d162a5c5fa02f802cc54ed616c3e3e252bf5b904dcb03861ee5a01f9
@@ -1,15 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MtLineEraser
2
4
  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')
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{|_file| _file.close}
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.3
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 00:00:00.000000000 Z
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: []