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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 421f575727d84ed7ab08ebcedc515fecb0a2dbcc
|
|
4
|
+
data.tar.gz: 2f32255ccbeb280172e6089afdc82a0425b1a8ff
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 941e68756b06ed527dac17f349f2edc9ca19d1c5f9a0eb1e0cc7ca911421f9d4703817e05bed36bf4e93693a399e1c279a4cc2b965cae3448d87e6f8dce01775
|
|
7
|
+
data.tar.gz: d6fa2b8be4f6335381c311c72ee2ec9add55486c7c537b4ca489a37405ebad49770c5d25c7f158093f93abc818c723bc3c736eb567312f12d3f64ba12eb6f6f1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 WitoldSlawko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Rft
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rft`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'rft'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install rft
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rft.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
# Ruby_Files_Tamer
|
|
42
|
+
Ruby project with File I/O handling.
|
|
43
|
+
|
|
44
|
+
### Options Commands with 1 parameter ###
|
|
45
|
+
$ rft -help # displays this info <br />
|
|
46
|
+
$ rft -folder # displays current working path <br />
|
|
47
|
+
|
|
48
|
+
### Options Commands with 2 parameters ###
|
|
49
|
+
$ rft filename.format -props # displays file properties <br />
|
|
50
|
+
|
|
51
|
+
### Access Commands with 1 paramater ###
|
|
52
|
+
$ rft filename.format # reads filename content <br />
|
|
53
|
+
$ rft --All # reads all files contents <br />
|
|
54
|
+
$ rft -list # lists all text-like files <br />
|
|
55
|
+
|
|
56
|
+
### Access Commands with 3 paramaters ###
|
|
57
|
+
$ rft filename.format -find phrase # searches for phrase in file and, if spoted, displays the lines <br />
|
|
58
|
+
$ rft --All -find phrase # searches for phrase in all textlike files and, if spoted, displays the lines <br />
|
|
59
|
+
$ rftfilename.format -uniqs uniqsname.format # creates new file with uniq phrases only <br />
|
|
60
|
+
|
|
61
|
+
### Mutation Commands with 2 parameters ###
|
|
62
|
+
$ rft filename.format -owtxt # overwrites text in file content by user input <br />
|
|
63
|
+
$ rft filename.format -apptxt # appends at the end of text in file content with user input <br />
|
|
64
|
+
$ rft filename.format -clr # clears the file content, and makes it a blank file <br />
|
|
65
|
+
$ rft filename.format -del # deletes the file <br />
|
|
66
|
+
$ rft --All -del # deletes all textlike files <br />
|
|
67
|
+
$ rft filename.format -new # creates new file by given filename.format <br />
|
|
68
|
+
|
|
69
|
+
### Mutation Commands with 3 parameters ###
|
|
70
|
+
$ rft filename.format -rename renamed.format # renames the file, can also change the format <br />
|
|
71
|
+
$ rft filename.format -rename renamed.format # renames the file, can also change the format <br />
|
|
72
|
+
$ rft filename.format -remove phrase # removes phrase from file <br />
|
|
73
|
+
$ rft --All -remove phrase # removes phrase from textlike files <br />
|
|
74
|
+
$ rft filename.format -copy new_file.format # copies all content from file to newly created new_file <br />
|
|
75
|
+
|
|
76
|
+
### Mutation Commands with 4 parameters ###
|
|
77
|
+
$ rft filename.format -rep from_phrase to_phrase # find/replace words in file by provided from_/to_ phrases <br />
|
|
78
|
+
$ rft --All -rep from_phrase to_phrase # find/replace words in all textlike files by provided from_/to_ phrases <br />
|
|
79
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "rft"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rft
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative '../lib/rft.rb'
|
|
3
|
+
|
|
4
|
+
#BEGIN {
|
|
5
|
+
|
|
6
|
+
$rft_path = File.expand_path File.dirname(__FILE__)
|
|
7
|
+
|
|
8
|
+
Dir.chdir ($rft_path)
|
|
9
|
+
Dir.chdir("../")
|
|
10
|
+
|
|
11
|
+
$folder_path = Dir.pwd
|
|
12
|
+
|
|
13
|
+
if File.file?(ARGV[0]) && ['.txt', '.md', '.otd', '.doc', '.docx'].any? { |format| ARGV[0].include?(format) }
|
|
14
|
+
$file_name = ARGV[0]
|
|
15
|
+
$file_path = File.expand_path File.dirname(__FILE__) + '/' +ARGV[0]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#}
|
|
19
|
+
|
|
20
|
+
def list
|
|
21
|
+
dir = Dir.entries($folder_path).join(' ').split(' ')
|
|
22
|
+
dir.delete('.') if dir.include? '.'
|
|
23
|
+
dir.delete('..') if dir.include? '..'
|
|
24
|
+
dir.each do |rm_file|
|
|
25
|
+
dir.delete(rm_file) unless rm_file.include? '.'
|
|
26
|
+
#dir.delete(rm_file) unless ['.txt', '.md', '.otd', '.doc', '.docx'].any? { |inc| rm_file.include? inc }
|
|
27
|
+
end
|
|
28
|
+
#dir.sort!
|
|
29
|
+
dir.each do |rm_file|
|
|
30
|
+
#dir.delete(rm_file) unless rm_file.include? '.'
|
|
31
|
+
dir.delete(rm_file) unless ['.txt', '.md', '.otd', '.doc', '.docx'].any? { |inc| rm_file.include? inc }
|
|
32
|
+
end
|
|
33
|
+
dir.sort!
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
case ARGV.length
|
|
37
|
+
|
|
38
|
+
when 1
|
|
39
|
+
Rft.reader($file_name) if File.file? ARGV[0]
|
|
40
|
+
|
|
41
|
+
case ARGV[0]
|
|
42
|
+
when '-list' then puts list
|
|
43
|
+
when '-help' then Rft.help
|
|
44
|
+
when '--All' then Rft.reader(list)
|
|
45
|
+
when '-folder' then Rft.folder
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
when 2
|
|
49
|
+
if File.file? ARGV[0]
|
|
50
|
+
case ARGV[1]
|
|
51
|
+
when '-props' then Rft.properties($file_name)
|
|
52
|
+
when '-owtxt' then Rft.overwrite_text($file_name)
|
|
53
|
+
when '-apptxt' then Rft.append_text($file_name)
|
|
54
|
+
when '-clr' then Rft.clear_text($file_name)
|
|
55
|
+
when '-del' then Rft.del($file_name)
|
|
56
|
+
else Rft.syntax_error
|
|
57
|
+
end
|
|
58
|
+
elsif ARGV[0] == '--A'
|
|
59
|
+
case ARGV[1]
|
|
60
|
+
when '-del' then Rft.del(list)
|
|
61
|
+
else Rft.syntax_error
|
|
62
|
+
end
|
|
63
|
+
elsif ARGV[0] == '-new'
|
|
64
|
+
unless list.include? ARGV[1]
|
|
65
|
+
Rft.create(ARGV[1])
|
|
66
|
+
else
|
|
67
|
+
puts "File " + ARGV[1] + " already exist!"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
when 3
|
|
72
|
+
if File.file? ARGV[0]
|
|
73
|
+
case ARGV[1]
|
|
74
|
+
when '-find' then Rft.seeker($file_name)
|
|
75
|
+
when '-rename' then Rft.rename($file_name, ARGV[2])
|
|
76
|
+
when '-copy' then Rft.copy($file_name, ARGV[2])
|
|
77
|
+
when '-remove' then Rft.remove($file_name, ARGV[2])
|
|
78
|
+
when '-uniqs' then Rft.uniqs($file_name, ARGV[2])
|
|
79
|
+
when '-end' then Rft.end_of_line($file_name, ARGV[2])
|
|
80
|
+
else Rft.syntax_error
|
|
81
|
+
end
|
|
82
|
+
elsif ARGV[0] == '--All'
|
|
83
|
+
case ARGV[1]
|
|
84
|
+
when '-find' then Rft.seeker(list)
|
|
85
|
+
when '-remove' then Rft.remove(list, ARGV[2])
|
|
86
|
+
else Rft.syntax_error
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
when 4
|
|
91
|
+
if File.file? ARGV[0]
|
|
92
|
+
case ARGV[1]
|
|
93
|
+
when '-rep' then replace($file_name, ARGV[3])
|
|
94
|
+
else Rft.syntax_error
|
|
95
|
+
end
|
|
96
|
+
elsif ARGV[0] == '--A'
|
|
97
|
+
case ARGV[1]
|
|
98
|
+
when '-rep' then replace(list, ARGV[3])
|
|
99
|
+
else Rft.syntax_error
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
data/bin/setup
ADDED
data/lib/rft.rb
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
require_relative "rft/version"
|
|
2
|
+
#require_relative "rft/options" # module Options
|
|
3
|
+
#require_relative "rft/access" # module Access
|
|
4
|
+
#require_relative "rft/mutation" # module Mutation
|
|
5
|
+
|
|
6
|
+
module Rft
|
|
7
|
+
|
|
8
|
+
# include Options ------------------------------------
|
|
9
|
+
|
|
10
|
+
def self.help
|
|
11
|
+
puts "HELP. Use rft.rb with following commands: "
|
|
12
|
+
puts " "
|
|
13
|
+
puts "### Options Commands with 1 parameter ###"
|
|
14
|
+
puts "$ rft -help # displays this info"
|
|
15
|
+
puts "$ rft -folder # displays current working path"
|
|
16
|
+
puts " "
|
|
17
|
+
puts "### Options Commands with 2 parameters ###"
|
|
18
|
+
puts "$ rft filename.format -props # displays file properties"
|
|
19
|
+
puts " "
|
|
20
|
+
puts "### Access Commands with 1 paramater ###"
|
|
21
|
+
puts "$ rft filename.format # reads filename content"
|
|
22
|
+
puts "$ rft --All # reads all files contents"
|
|
23
|
+
puts "$ rft -list # lists all text-like files"
|
|
24
|
+
puts " "
|
|
25
|
+
puts "### Access Commands with 3 paramaters ###"
|
|
26
|
+
puts "$ rft filename.format -find phrase # searches for phrase in file and, if spoted, displays the lines"
|
|
27
|
+
puts "$ rft --All -find phrase # searches for phrase in all textlike files and, if spoted, displays the lines"
|
|
28
|
+
puts "$ rftfilename.format -uniqs uniqsname.format # creates new file with uniq phrases only"
|
|
29
|
+
puts " "
|
|
30
|
+
puts "### Mutation Commands with 2 parameters ###"
|
|
31
|
+
puts "$ rft filename.format -owtxt # overwrites text in file content by user input"
|
|
32
|
+
puts "$ rft filename.format -apptxt # appends at the end of text in file content with user input"
|
|
33
|
+
puts "$ rft filename.format -clr # clears the file content, and makes it a blank file"
|
|
34
|
+
puts "$ rft filename.format -del # deletes the file"
|
|
35
|
+
puts "$ rft --All -del # deletes all textlike files"
|
|
36
|
+
puts "$ rft filename.format -new # creates new file by given filename.format" + '\n'
|
|
37
|
+
puts " "
|
|
38
|
+
puts "### Mutation Commands with 3 parameters ###"
|
|
39
|
+
puts "$ rft filename.format -rename renamed.format # renames the file, can also change the format"
|
|
40
|
+
puts "$ rft filename.format -rename renamed.format # renames the file, can also change the format"
|
|
41
|
+
puts "$ rft filename.format -remove phrase # removes phrase from file"
|
|
42
|
+
puts "$ rft --All -remove phrase # removes phrase from textlike files"
|
|
43
|
+
puts "$ rft filename.format -copy new_file.format # copies all content from file to newly created new_file"
|
|
44
|
+
puts " "
|
|
45
|
+
puts "### Mutation Commands with 4 parameters ###"
|
|
46
|
+
puts "$ rft filename.format -rep from_phrase to_phrase # find/replace words in file by provided from_/to_ phrases"
|
|
47
|
+
puts "$ rft --All -rep from_phrase to_phrase # find/replace words in all textlike files by provided from_/to_ phrases"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.folder
|
|
51
|
+
puts $folder_path
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.properties(file_props)
|
|
55
|
+
puts "Name: " + file_props
|
|
56
|
+
puts "Type: " + File::ftype(file_props)
|
|
57
|
+
puts "Format: " + file_props[file_props.index('.')+1, file_props.length-1]
|
|
58
|
+
puts "Empty? " + File.zero?(file_props).to_s
|
|
59
|
+
if File.size?(file_props) < 1024
|
|
60
|
+
puts "Size: " + File.size?(file_props).to_s + ' bytes'
|
|
61
|
+
elsif File.size?(file_props) >= 1024 && File.size?(file_props) < (1024**2)
|
|
62
|
+
puts "Size: " + (File.size?(file_props)/1024.0).ceil(2).to_s + ' KB'
|
|
63
|
+
else File.size?(file_props) >= (1024**2)
|
|
64
|
+
puts "Size: " + (File.size?(file_props)/(1024.0**2)).ceil(2).to_s + ' MB'
|
|
65
|
+
end
|
|
66
|
+
puts "Readable? " + File.readable?(file_props).to_s
|
|
67
|
+
puts "Writable? " + File.writable?(file_props).to_s
|
|
68
|
+
puts "Executable? " + File.executable?(file_props).to_s
|
|
69
|
+
puts "Created: " + File::ctime(file_props).to_s
|
|
70
|
+
puts "Modified: " + File::mtime(file_props).to_s
|
|
71
|
+
puts "Accessed: " + File::atime(file_props).to_s
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.syntax_error
|
|
75
|
+
puts "RFT: Wrong syntax! Type: $ ruby rft.rb -h # for help!"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# include Mutation ------------------------------------
|
|
79
|
+
|
|
80
|
+
def self.create(to_create)
|
|
81
|
+
File.open(to_create, "w");
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.overwrite_text(to_overwrite)
|
|
85
|
+
puts "Write text to " + to_write + ' :'
|
|
86
|
+
new_text = STDIN.gets.chomp
|
|
87
|
+
File.open(to_write, "w").syswrite(new_text)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.append_text(to_write)
|
|
91
|
+
puts "Append text to " + to_write + ' :'
|
|
92
|
+
new_text = STDIN.gets.chomp
|
|
93
|
+
File.open(to_write, "a+") do |line|
|
|
94
|
+
line.puts "\n" + "Following text was added at: " +Time.now.inspect + " \n"+ new_text + "\n"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.end_of_line(to_add, end_line)
|
|
99
|
+
arr_lines = IO.readlines(to_add)
|
|
100
|
+
arr_lines.each do |ending|
|
|
101
|
+
ending += end_line
|
|
102
|
+
end
|
|
103
|
+
puts arr_lines
|
|
104
|
+
end_file = File.new(to_add, "w+")
|
|
105
|
+
for ender in 0...arr_lines.length
|
|
106
|
+
end_file.syswrite(arr_lines[ender])
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.clear_text(to_clear)
|
|
111
|
+
File.open(to_clear, "w").syswrite('')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def self.rename(from, to)
|
|
115
|
+
File.rename(from, to)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.replace(to_rep, with_word)
|
|
119
|
+
if to_rep.is_a? String
|
|
120
|
+
arr_lines = IO.readlines(to_rep)
|
|
121
|
+
arr_lines.each do |replacer|
|
|
122
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
123
|
+
end
|
|
124
|
+
rep_file = File.new(to_rep, "w");
|
|
125
|
+
for rep in 0...arr_lines.length do
|
|
126
|
+
rep_file.syswrite(arr_lines[rep])
|
|
127
|
+
end
|
|
128
|
+
elsif to_rep.is_a? Array
|
|
129
|
+
to_rep.each do |replacement|
|
|
130
|
+
arr_lines = IO.readlines(replacement)
|
|
131
|
+
arr_lines.each do |replacer|
|
|
132
|
+
replacer.gsub!(/#{ARGV[2]}/, with_word )
|
|
133
|
+
end
|
|
134
|
+
rep_file = File.new(replacement, "w");
|
|
135
|
+
for rep in 0...arr_lines.length do
|
|
136
|
+
rep_file.syswrite(arr_lines[rep])
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.copy(to_copy, new_name)
|
|
143
|
+
arr_lines = IO.readlines(to_copy)
|
|
144
|
+
rep_file = File.new(new_name, "w");
|
|
145
|
+
for rep in 0...arr_lines.length do
|
|
146
|
+
rep_file.syswrite(arr_lines[rep])
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.remove(to_file, to_remove)
|
|
151
|
+
if to_file.is_a? String
|
|
152
|
+
arr_lines = IO.readlines(to_file)
|
|
153
|
+
arr_lines.each do |remover|
|
|
154
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
155
|
+
end
|
|
156
|
+
rep_file = File.new(to_file, "w");
|
|
157
|
+
for rep in 0...arr_lines.length do
|
|
158
|
+
rep_file.syswrite(arr_lines[rep])
|
|
159
|
+
end
|
|
160
|
+
elsif to_remove.is_a? Array
|
|
161
|
+
to_remove.each do |removement|
|
|
162
|
+
arr_lines = IO.readlines(removement)
|
|
163
|
+
arr_lines.each do |remover|
|
|
164
|
+
remover.gsub!(/#{to_remove}/, '' )
|
|
165
|
+
end
|
|
166
|
+
rep_file = File.new(removement, "w");
|
|
167
|
+
for rep in 0...arr_lines.length do
|
|
168
|
+
rep_file.syswrite(arr_lines[rep])
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def self.del(to_delete)
|
|
175
|
+
if to_delete.is_a? String
|
|
176
|
+
File.delete(to_delete)
|
|
177
|
+
elsif to_delete.is_a? Array
|
|
178
|
+
to_delete.each do |to_del|
|
|
179
|
+
File.delete(to_del)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
# include Access
|
|
184
|
+
#module Access
|
|
185
|
+
|
|
186
|
+
def self.reader(to_read)
|
|
187
|
+
if to_read.is_a? String
|
|
188
|
+
num_lines = 0
|
|
189
|
+
puts $folder_path + '/' + to_read
|
|
190
|
+
File.open(to_read, "r").each do |line|
|
|
191
|
+
puts "#{num_lines += 1} | " + line
|
|
192
|
+
end
|
|
193
|
+
elsif to_read.is_a? Array
|
|
194
|
+
to_read.each do |file|
|
|
195
|
+
self.reader(file)
|
|
196
|
+
puts ' '
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def self.seeker(to_seek)
|
|
202
|
+
if to_seek.is_a? String
|
|
203
|
+
num_lines = 0
|
|
204
|
+
puts $path_file
|
|
205
|
+
File.open(to_seek, "r").each do |line|
|
|
206
|
+
"#{num_lines += 1} | " + line
|
|
207
|
+
print "#{num_lines} | " + line if line.include? ARGV[2]
|
|
208
|
+
end
|
|
209
|
+
elsif to_seek.is_a? Array
|
|
210
|
+
path = File.expand_path File.dirname(__FILE__)
|
|
211
|
+
to_seek.each do |file|
|
|
212
|
+
print path + '/' + file
|
|
213
|
+
self.seeker(file)
|
|
214
|
+
puts ' '
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def self.uniqs(to_uniq, the_uniqs)
|
|
220
|
+
if to_uniq.is_a? String
|
|
221
|
+
arr_lines = IO.readlines(to_uniq)
|
|
222
|
+
arr_flat = []
|
|
223
|
+
for unq in 0...arr_lines.length do
|
|
224
|
+
arr_flat << arr_lines[unq].split(" ")
|
|
225
|
+
arr_flat.uniq!
|
|
226
|
+
end
|
|
227
|
+
arr_flat.flatten!
|
|
228
|
+
uniqs_file = File.new(the_uniqs, "w")
|
|
229
|
+
for un in 0...arr_flat.length do
|
|
230
|
+
uniqs_file.syswrite(arr_flat[un] + "\n")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
end
|