rft 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/rft +103 -0
- data/bin/setup +8 -0
- data/lib/rft.rb +236 -0
- data/lib/rft/access.rb +52 -0
- data/lib/rft/mutation.rb +107 -0
- data/lib/rft/options.rb +71 -0
- data/lib/rft/version.rb +3 -0
- data/rft-0.1.0.gem +0 -0
- data/rft.gemspec +37 -0
- data/rft_raw_files/RFT/modules_rft/access.rb +52 -0
- data/rft_raw_files/RFT/modules_rft/mutation.rb +107 -0
- data/rft_raw_files/RFT/modules_rft/options.rb +71 -0
- data/rft_raw_files/RFT/rft.rb +106 -0
- data/rft_raw_files/abcedf.txt +3 -0
- data/rft_raw_files/b.txt +5 -0
- data/rft_raw_files/c.txt +3 -0
- data/rft_raw_files/how_to_rft.md +39 -0
- data/rft_raw_files/neo.txt +6 -0
- data/rft_raw_files/ri_sources.md +702 -0
- data/rft_raw_files/test_file_1.txt +5 -0
- metadata +99 -0
data/lib/rft/access.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Access
|
|
2
|
+
|
|
3
|
+
def self.reader(to_read)
|
|
4
|
+
if to_read.is_a? String
|
|
5
|
+
num_lines = 0
|
|
6
|
+
puts $folder_path + '/' + to_read
|
|
7
|
+
File.open(to_read, "r").each do |line|
|
|
8
|
+
puts "#{num_lines += 1} | " + line
|
|
9
|
+
end
|
|
10
|
+
elsif to_read.is_a? Array
|
|
11
|
+
to_read.each do |file|
|
|
12
|
+
self.reader(file)
|
|
13
|
+
puts ' '
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.seeker(to_seek)
|
|
19
|
+
if to_seek.is_a? String
|
|
20
|
+
num_lines = 0
|
|
21
|
+
puts $path_file
|
|
22
|
+
File.open(to_seek, "r").each do |line|
|
|
23
|
+
"#{num_lines += 1} | " + line
|
|
24
|
+
print "#{num_lines} | " + line if line.include? ARGV[2]
|
|
25
|
+
end
|
|
26
|
+
elsif to_seek.is_a? Array
|
|
27
|
+
path = File.expand_path File.dirname(__FILE__)
|
|
28
|
+
to_seek.each do |file|
|
|
29
|
+
print path + '/' + file
|
|
30
|
+
self.seeker(file)
|
|
31
|
+
puts ' '
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.uniqs(to_uniq, the_uniqs)
|
|
37
|
+
if to_uniq.is_a? String
|
|
38
|
+
arr_lines = IO.readlines(to_uniq)
|
|
39
|
+
arr_flat = []
|
|
40
|
+
for unq in 0...arr_lines.length do
|
|
41
|
+
arr_flat << arr_lines[unq].split(" ")
|
|
42
|
+
arr_flat.uniq!
|
|
43
|
+
end
|
|
44
|
+
arr_flat.flatten!
|
|
45
|
+
uniqs_file = File.new(the_uniqs, "w")
|
|
46
|
+
for un in 0...arr_flat.length do
|
|
47
|
+
uniqs_file.syswrite(arr_flat[un] + "\n")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
data/lib/rft/mutation.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
module Mutation
|
|
2
|
+
|
|
3
|
+
def self.create(to_create)
|
|
4
|
+
File.open(to_create, "w");
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.overwrite_text(to_overwrite)
|
|
8
|
+
puts "Write text to " + to_write + ' :'
|
|
9
|
+
new_text = STDIN.gets.chomp
|
|
10
|
+
File.open(to_write, "w").syswrite(new_text)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.append_text(to_write)
|
|
14
|
+
puts "Append text to " + to_write + ' :'
|
|
15
|
+
new_text = STDIN.gets.chomp
|
|
16
|
+
File.open(to_write, "a+") do |line|
|
|
17
|
+
line.puts "\n" + "Following text was added at: " +Time.now.inspect + " \n"+ new_text + "\n"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.end_of_line(to_add, end_line)
|
|
22
|
+
arr_lines = IO.readlines(to_add)
|
|
23
|
+
arr_lines.collect! do |ending|
|
|
24
|
+
ending += end_line + "\n"
|
|
25
|
+
end
|
|
26
|
+
#puts arr_lines
|
|
27
|
+
end_file = File.new(to_add, "w+")
|
|
28
|
+
for ender in 0...arr_lines.length
|
|
29
|
+
end_file.syswrite(arr_lines[ender])
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.clear_text(to_clear)
|
|
34
|
+
File.open(to_clear, "w").syswrite('')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.rename(from, to)
|
|
38
|
+
File.rename(from, to)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.replace(to_rep, with_word)
|
|
42
|
+
if to_rep.is_a? String
|
|
43
|
+
arr_lines = IO.readlines(to_rep)
|
|
44
|
+
arr_lines.each do |replacer|
|
|
45
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
46
|
+
end
|
|
47
|
+
rep_file = File.new(to_rep, "w");
|
|
48
|
+
for rep in 0...arr_lines.length do
|
|
49
|
+
rep_file.syswrite(arr_lines[rep])
|
|
50
|
+
end
|
|
51
|
+
elsif to_rep.is_a? Array
|
|
52
|
+
to_rep.each do |replacement|
|
|
53
|
+
arr_lines = IO.readlines(replacement)
|
|
54
|
+
arr_lines.each do |replacer|
|
|
55
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
56
|
+
end
|
|
57
|
+
rep_file = File.new(replacement, "w");
|
|
58
|
+
for rep in 0...arr_lines.length do
|
|
59
|
+
rep_file.syswrite(arr_lines[rep])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.copy(to_copy, new_name)
|
|
66
|
+
arr_lines = IO.readlines(to_copy)
|
|
67
|
+
rep_file = File.new(new_name, "w");
|
|
68
|
+
for rep in 0...arr_lines.length do
|
|
69
|
+
rep_file.syswrite(arr_lines[rep])
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.remove(to_file, to_remove)
|
|
74
|
+
if to_file.is_a? String
|
|
75
|
+
arr_lines = IO.readlines(to_file)
|
|
76
|
+
arr_lines.each do |remover|
|
|
77
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
78
|
+
end
|
|
79
|
+
rep_file = File.new(to_file, "w");
|
|
80
|
+
for rep in 0...arr_lines.length do
|
|
81
|
+
rep_file.syswrite(arr_lines[rep])
|
|
82
|
+
end
|
|
83
|
+
elsif to_remove.is_a? Array
|
|
84
|
+
to_remove.each do |removement|
|
|
85
|
+
arr_lines = IO.readlines(removement)
|
|
86
|
+
arr_lines.each do |remover|
|
|
87
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
88
|
+
end
|
|
89
|
+
rep_file = File.new(removement, "w");
|
|
90
|
+
for rep in 0...arr_lines.length do
|
|
91
|
+
rep_file.syswrite(arr_lines[rep])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.del(to_delete)
|
|
98
|
+
if to_delete.is_a? String
|
|
99
|
+
File.delete(to_delete)
|
|
100
|
+
elsif to_delete.is_a? Array
|
|
101
|
+
to_delete.each do |to_del|
|
|
102
|
+
File.delete(to_del)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
data/lib/rft/options.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Options
|
|
2
|
+
|
|
3
|
+
def self.help
|
|
4
|
+
puts "HELP. Use rft.rb with following commands: "
|
|
5
|
+
puts " "
|
|
6
|
+
puts "### Options Commands with 1 parameter ###"
|
|
7
|
+
puts "$ ruby RFT/rft.rb -help # displays this info"
|
|
8
|
+
puts "$ ruby RFT/rft.rb -folder # displays current working path"
|
|
9
|
+
puts " "
|
|
10
|
+
puts "### Options Commands with 2 parameters ###"
|
|
11
|
+
puts "$ ruby RFT/rft.rb filename.format -props # displays file properties"
|
|
12
|
+
puts " "
|
|
13
|
+
puts "### Access Commands with 1 paramater ###"
|
|
14
|
+
puts "$ ruby RFT/rft.rb filename.format # reads filename content"
|
|
15
|
+
puts "$ ruby RFT/rft.rb --All # reads all files contents"
|
|
16
|
+
puts "$ ruby RFT/rft.rb -list # lists all text-like files"
|
|
17
|
+
puts " "
|
|
18
|
+
puts "### Access Commands with 3 paramaters ###"
|
|
19
|
+
puts "$ ruby RFT/rft.rb filename.format -find phrase # searches for phrase in file and, if spoted, displays the lines"
|
|
20
|
+
puts "$ ruby RFT/rft.rb --All -find phrase # searches for phrase in all textlike files and, if spoted, displays the lines"
|
|
21
|
+
puts "$ ruby RFT/rft.rbfilename.format -uniqs uniqsname.format # creates new file with uniq phrases only"
|
|
22
|
+
puts " "
|
|
23
|
+
puts "### Mutation Commands with 2 parameters ###"
|
|
24
|
+
puts "$ ruby RFT/rft.rb filename.format -owtxt # overwrites text in file content by user input"
|
|
25
|
+
puts "$ ruby RFT/rft.rb filename.format -apptxt # appends at the end of text in file content with user input"
|
|
26
|
+
puts "$ ruby RFT/rft.rb filename.format -clr # clears the file content, and makes it a blank file"
|
|
27
|
+
puts "$ ruby RFT/rft.rb filename.format -del # deletes the file"
|
|
28
|
+
puts "$ ruby RFT/rft.rb --All -del # deletes all textlike files"
|
|
29
|
+
puts "$ ruby RFT/rft.rb filename.format -new # creates new file by given filename.format" + '\n'
|
|
30
|
+
puts " "
|
|
31
|
+
puts "### Mutation Commands with 3 parameters ###"
|
|
32
|
+
puts "$ ruby RFT/rft.rb filename.format -rename renamed.format # renames the file, can also change the format"
|
|
33
|
+
puts "$ ruby RFT/rft.rb filename.format -rename renamed.format # renames the file, can also change the format"
|
|
34
|
+
puts "$ ruby RFT/rft.rb filename.format -remove phrase # removes phrase from file"
|
|
35
|
+
puts "$ ruby RFT/rft.rb --All -remove phrase # removes phrase from textlike files"
|
|
36
|
+
puts "$ ruby RFT/rft.rb filename.format -copy new_file.format # copies all content from file to newly created new_file"
|
|
37
|
+
puts " "
|
|
38
|
+
puts "### Mutation Commands with 4 parameters ###"
|
|
39
|
+
puts "$ ruby RFT/rft.rb filename.format -rep from_phrase to_phrase # find/replace words in file by provided from_/to_ phrases"
|
|
40
|
+
puts "$ ruby RFT/rft.rb --All -rep from_phrase to_phrase # find/replace words in all textlike files by provided from_/to_ phrases"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.folder
|
|
44
|
+
puts $folder_path
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.properties(file_props)
|
|
48
|
+
puts "Name: " + file_props
|
|
49
|
+
puts "Type: " + File::ftype(file_props)
|
|
50
|
+
puts "Format: " + file_props[file_props.index('.')+1, file_props.length-1]
|
|
51
|
+
puts "Empty? " + File.zero?(file_props).to_s
|
|
52
|
+
if File.size?(file_props) < 1024
|
|
53
|
+
puts "Size: " + File.size?(file_props).to_s + ' bytes'
|
|
54
|
+
elsif File.size?(file_props) >= 1024 && File.size?(file_props) < (1024**2)
|
|
55
|
+
puts "Size: " + (File.size?(file_props)/1024.0).ceil(2).to_s + ' KB'
|
|
56
|
+
else File.size?(file_props) >= (1024**2)
|
|
57
|
+
puts "Size: " + (File.size?(file_props)/(1024.0**2)).ceil(2).to_s + ' MB'
|
|
58
|
+
end
|
|
59
|
+
puts "Readable? " + File.readable?(file_props).to_s
|
|
60
|
+
puts "Writable? " + File.writable?(file_props).to_s
|
|
61
|
+
puts "Executable? " + File.executable?(file_props).to_s
|
|
62
|
+
puts "Created: " + File::ctime(file_props).to_s
|
|
63
|
+
puts "Modified: " + File::mtime(file_props).to_s
|
|
64
|
+
puts "Accessed: " + File::atime(file_props).to_s
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.syntax_error
|
|
68
|
+
puts "RFT: Wrong syntax! Type: $ ruby rft.rb -h # for help!"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
data/lib/rft/version.rb
ADDED
data/rft-0.1.0.gem
ADDED
|
Binary file
|
data/rft.gemspec
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "rft/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "rft"
|
|
8
|
+
spec.version = Rft::VERSION
|
|
9
|
+
spec.authors = ["WitoldSlawko"]
|
|
10
|
+
spec.email = ["witold.slawko@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
|
|
13
|
+
spec.description = %q{Ruby Files Tamer - command line app for text files.}
|
|
14
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
|
15
|
+
spec.homepage = "https://github.com/WitoldSlawko/Ruby_Files_Tamer"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
#if spec.respond_to?(:metadata)
|
|
21
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
22
|
+
#else
|
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
24
|
+
# "public gem pushes."
|
|
25
|
+
#end
|
|
26
|
+
|
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
|
29
|
+
end
|
|
30
|
+
# spec.bindir = "exe"
|
|
31
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.executables << "rft"
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
37
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Access
|
|
2
|
+
|
|
3
|
+
def self.reader(to_read)
|
|
4
|
+
if to_read.is_a? String
|
|
5
|
+
num_lines = 0
|
|
6
|
+
puts $folder_path + '/' + to_read
|
|
7
|
+
File.open(to_read, "r").each do |line|
|
|
8
|
+
puts "#{num_lines += 1} | " + line
|
|
9
|
+
end
|
|
10
|
+
elsif to_read.is_a? Array
|
|
11
|
+
to_read.each do |file|
|
|
12
|
+
self.reader(file)
|
|
13
|
+
puts ' '
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.seeker(to_seek)
|
|
19
|
+
if to_seek.is_a? String
|
|
20
|
+
num_lines = 0
|
|
21
|
+
puts $path_file
|
|
22
|
+
File.open(to_seek, "r").each do |line|
|
|
23
|
+
"#{num_lines += 1} | " + line
|
|
24
|
+
print "#{num_lines} | " + line if line.include? ARGV[2]
|
|
25
|
+
end
|
|
26
|
+
elsif to_seek.is_a? Array
|
|
27
|
+
path = File.expand_path File.dirname(__FILE__)
|
|
28
|
+
to_seek.each do |file|
|
|
29
|
+
print path + '/' + file
|
|
30
|
+
self.seeker(file)
|
|
31
|
+
puts ' '
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.uniqs(to_uniq, the_uniqs)
|
|
37
|
+
if to_uniq.is_a? String
|
|
38
|
+
arr_lines = IO.readlines(to_uniq)
|
|
39
|
+
arr_flat = []
|
|
40
|
+
for unq in 0...arr_lines.length do
|
|
41
|
+
arr_flat << arr_lines[unq].split(" ")
|
|
42
|
+
arr_flat.uniq!
|
|
43
|
+
end
|
|
44
|
+
arr_flat.flatten!
|
|
45
|
+
uniqs_file = File.new(the_uniqs, "w")
|
|
46
|
+
for un in 0...arr_flat.length do
|
|
47
|
+
uniqs_file.syswrite(arr_flat[un] + "\n")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
module Mutation
|
|
2
|
+
|
|
3
|
+
def self.create(to_create)
|
|
4
|
+
File.open(to_create, "w");
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.overwrite_text(to_overwrite)
|
|
8
|
+
puts "Write text to " + to_write + ' :'
|
|
9
|
+
new_text = STDIN.gets.chomp
|
|
10
|
+
File.open(to_write, "w").syswrite(new_text)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.append_text(to_write)
|
|
14
|
+
puts "Append text to " + to_write + ' :'
|
|
15
|
+
new_text = STDIN.gets.chomp
|
|
16
|
+
File.open(to_write, "a+") do |line|
|
|
17
|
+
line.puts "\n" + "Following text was added at: " +Time.now.inspect + " \n"+ new_text + "\n"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.end_of_line(to_add, end_line)
|
|
22
|
+
arr_lines = IO.readlines(to_add)
|
|
23
|
+
arr_lines.each do |ending|
|
|
24
|
+
ending += end_line
|
|
25
|
+
end
|
|
26
|
+
puts arr_lines
|
|
27
|
+
end_file = File.new(to_add, "w+")
|
|
28
|
+
for ender in 0...arr_lines.length
|
|
29
|
+
end_file.syswrite(arr_lines[ender])
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.clear_text(to_clear)
|
|
34
|
+
File.open(to_clear, "w").syswrite('')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.rename(from, to)
|
|
38
|
+
File.rename(from, to)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.replace(to_rep, with_word)
|
|
42
|
+
if to_rep.is_a? String
|
|
43
|
+
arr_lines = IO.readlines(to_rep)
|
|
44
|
+
arr_lines.each do |replacer|
|
|
45
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
46
|
+
end
|
|
47
|
+
rep_file = File.new(to_rep, "w");
|
|
48
|
+
for rep in 0...arr_lines.length do
|
|
49
|
+
rep_file.syswrite(arr_lines[rep])
|
|
50
|
+
end
|
|
51
|
+
elsif to_rep.is_a? Array
|
|
52
|
+
to_rep.each do |replacement|
|
|
53
|
+
arr_lines = IO.readlines(replacement)
|
|
54
|
+
arr_lines.each do |replacer|
|
|
55
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
56
|
+
end
|
|
57
|
+
rep_file = File.new(replacement, "w");
|
|
58
|
+
for rep in 0...arr_lines.length do
|
|
59
|
+
rep_file.syswrite(arr_lines[rep])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.copy(to_copy, new_name)
|
|
66
|
+
arr_lines = IO.readlines(to_copy)
|
|
67
|
+
rep_file = File.new(new_name, "w");
|
|
68
|
+
for rep in 0...arr_lines.length do
|
|
69
|
+
rep_file.syswrite(arr_lines[rep])
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.remove(to_file, to_remove)
|
|
74
|
+
if to_file.is_a? String
|
|
75
|
+
arr_lines = IO.readlines(to_file)
|
|
76
|
+
arr_lines.each do |remover|
|
|
77
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
78
|
+
end
|
|
79
|
+
rep_file = File.new(to_file, "w");
|
|
80
|
+
for rep in 0...arr_lines.length do
|
|
81
|
+
rep_file.syswrite(arr_lines[rep])
|
|
82
|
+
end
|
|
83
|
+
elsif to_remove.is_a? Array
|
|
84
|
+
to_remove.each do |removement|
|
|
85
|
+
arr_lines = IO.readlines(removement)
|
|
86
|
+
arr_lines.each do |remover|
|
|
87
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
88
|
+
end
|
|
89
|
+
rep_file = File.new(removement, "w");
|
|
90
|
+
for rep in 0...arr_lines.length do
|
|
91
|
+
rep_file.syswrite(arr_lines[rep])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.del(to_delete)
|
|
98
|
+
if to_delete.is_a? String
|
|
99
|
+
File.delete(to_delete)
|
|
100
|
+
elsif to_delete.is_a? Array
|
|
101
|
+
to_delete.each do |to_del|
|
|
102
|
+
File.delete(to_del)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Options
|
|
2
|
+
|
|
3
|
+
def self.help
|
|
4
|
+
puts "HELP. Use rft.rb with following commands: "
|
|
5
|
+
puts " "
|
|
6
|
+
puts "### Options Commands with 1 parameter ###"
|
|
7
|
+
puts "$ ruby RFT/rft.rb -help # displays this info"
|
|
8
|
+
puts "$ ruby RFT/rft.rb -folder # displays current working path"
|
|
9
|
+
puts " "
|
|
10
|
+
puts "### Options Commands with 2 parameters ###"
|
|
11
|
+
puts "$ ruby RFT/rft.rb filename.format -props # displays file properties"
|
|
12
|
+
puts " "
|
|
13
|
+
puts "### Access Commands with 1 paramater ###"
|
|
14
|
+
puts "$ ruby RFT/rft.rb filename.format # reads filename content"
|
|
15
|
+
puts "$ ruby RFT/rft.rb --All # reads all files contents"
|
|
16
|
+
puts "$ ruby RFT/rft.rb -list # lists all text-like files"
|
|
17
|
+
puts " "
|
|
18
|
+
puts "### Access Commands with 3 paramaters ###"
|
|
19
|
+
puts "$ ruby RFT/rft.rb filename.format -find phrase # searches for phrase in file and, if spoted, displays the lines"
|
|
20
|
+
puts "$ ruby RFT/rft.rb --All -find phrase # searches for phrase in all textlike files and, if spoted, displays the lines"
|
|
21
|
+
puts "$ ruby RFT/rft.rbfilename.format -uniqs uniqsname.format # creates new file with uniq phrases only"
|
|
22
|
+
puts " "
|
|
23
|
+
puts "### Mutation Commands with 2 parameters ###"
|
|
24
|
+
puts "$ ruby RFT/rft.rb filename.format -owtxt # overwrites text in file content by user input"
|
|
25
|
+
puts "$ ruby RFT/rft.rb filename.format -apptxt # appends at the end of text in file content with user input"
|
|
26
|
+
puts "$ ruby RFT/rft.rb filename.format -clr # clears the file content, and makes it a blank file"
|
|
27
|
+
puts "$ ruby RFT/rft.rb filename.format -del # deletes the file"
|
|
28
|
+
puts "$ ruby RFT/rft.rb --All -del # deletes all textlike files"
|
|
29
|
+
puts "$ ruby RFT/rft.rb filename.format -new # creates new file by given filename.format" + '\n'
|
|
30
|
+
puts " "
|
|
31
|
+
puts "### Mutation Commands with 3 parameters ###"
|
|
32
|
+
puts "$ ruby RFT/rft.rb filename.format -rename renamed.format # renames the file, can also change the format"
|
|
33
|
+
puts "$ ruby RFT/rft.rb filename.format -rename renamed.format # renames the file, can also change the format"
|
|
34
|
+
puts "$ ruby RFT/rft.rb filename.format -remove phrase # removes phrase from file"
|
|
35
|
+
puts "$ ruby RFT/rft.rb --All -remove phrase # removes phrase from textlike files"
|
|
36
|
+
puts "$ ruby RFT/rft.rb filename.format -copy new_file.format # copies all content from file to newly created new_file"
|
|
37
|
+
puts " "
|
|
38
|
+
puts "### Mutation Commands with 4 parameters ###"
|
|
39
|
+
puts "$ ruby RFT/rft.rb filename.format -rep from_phrase to_phrase # find/replace words in file by provided from_/to_ phrases"
|
|
40
|
+
puts "$ ruby RFT/rft.rb --All -rep from_phrase to_phrase # find/replace words in all textlike files by provided from_/to_ phrases"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.folder
|
|
44
|
+
puts $folder_path
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.properties(file_props)
|
|
48
|
+
puts "Name: " + file_props
|
|
49
|
+
puts "Type: " + File::ftype(file_props)
|
|
50
|
+
puts "Format: " + file_props[file_props.index('.')+1, file_props.length-1]
|
|
51
|
+
puts "Empty? " + File.zero?(file_props).to_s
|
|
52
|
+
if File.size?(file_props) < 1024
|
|
53
|
+
puts "Size: " + File.size?(file_props).to_s + ' bytes'
|
|
54
|
+
elsif File.size?(file_props) >= 1024 && File.size?(file_props) < (1024**2)
|
|
55
|
+
puts "Size: " + (File.size?(file_props)/1024.0).ceil(2).to_s + ' KB'
|
|
56
|
+
else File.size?(file_props) >= (1024**2)
|
|
57
|
+
puts "Size: " + (File.size?(file_props)/(1024.0**2)).ceil(2).to_s + ' MB'
|
|
58
|
+
end
|
|
59
|
+
puts "Readable? " + File.readable?(file_props).to_s
|
|
60
|
+
puts "Writable? " + File.writable?(file_props).to_s
|
|
61
|
+
puts "Executable? " + File.executable?(file_props).to_s
|
|
62
|
+
puts "Created: " + File::ctime(file_props).to_s
|
|
63
|
+
puts "Modified: " + File::mtime(file_props).to_s
|
|
64
|
+
puts "Accessed: " + File::atime(file_props).to_s
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.syntax_error
|
|
68
|
+
puts "RFT: Wrong syntax! Type: $ ruby rft.rb -h # for help!"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|