Module: Dunlop::FileGrep
- Defined in:
- app/services/dunlop/file_grep.rb
Class Method Summary collapse
- .egrep(input_filename, output_filename, regexp) ⇒ Object
- .egrep_v(input_filename, output_filename, regexp) ⇒ Object
- .filter(input_filename, regexp_string, filter_method: :egrep) ⇒ Object
- .reject(input_filename, regexp_string) ⇒ Object
- .select(input_filename, regexp_string) ⇒ Object
Class Method Details
.egrep(input_filename, output_filename, regexp) ⇒ Object
3 4 5 |
# File 'app/services/dunlop/file_grep.rb', line 3 def self.egrep( input_filename, output_filename, regexp ) %x[egrep '#{regexp}' #{input_filename} > #{output_filename}] end |
.egrep_v(input_filename, output_filename, regexp) ⇒ Object
7 8 9 |
# File 'app/services/dunlop/file_grep.rb', line 7 def self.egrep_v( input_filename, output_filename, regexp ) %x[egrep -v '#{regexp}' #{input_filename} > #{output_filename}] end |
.filter(input_filename, regexp_string, filter_method: :egrep) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/services/dunlop/file_grep.rb', line 15 def self.filter(input_filename, regexp_string, filter_method: :egrep) local_working_file = Tempfile.new("file_grep", WORKING_PATH) #egrep(input_filename, local_working_file.path, regexp_string) public_send(filter_method, input_filename, local_working_file.path, regexp_string) FileUtils.cp(local_working_file.path, input_filename) FileUtils.chmod(0644, input_filename) ensure local_working_file.unlink end |
.reject(input_filename, regexp_string) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/services/dunlop/file_grep.rb', line 25 def self.reject(input_filename, regexp_string) filter input_filename, regexp_string, filter_method: :egrep_v #local_working_file = Tempfile.new("file_grep", WORKING_PATH) #egrep_v(input_filename, local_working_file.path, regexp_string) #FileUtils.cp(local_working_file.path, input_filename) #FileUtils.chmod(0644, input_filename) #ensure #local_working_file.unlink end |
.select(input_filename, regexp_string) ⇒ Object
11 12 13 |
# File 'app/services/dunlop/file_grep.rb', line 11 def self.select(input_filename, regexp_string) filter input_filename, regexp_string, filter_method: :egrep end |