rubisc 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c56a1a56b21eac8389be963efabd095f03292d39
4
+ data.tar.gz: c51b98af75ffda3d89102998bcfd91bbd1661bd7
5
+ SHA512:
6
+ metadata.gz: f45aa30eccc55edd115ef8dfc1f0aebad7c77f349ce6ffcef607f41b02f43148bee5937de0fbcbcfedf634f4497e7c873aec376a208e1ffa0f29cd11e9badd9a
7
+ data.tar.gz: 01d7fa8c9313b82e9a4d361f592c2874ab2b38d1612b77634010c0df45429548de33b574e0dbe01ff8c626d7ddc20873d335263d86935c80196be75bf307e4cb
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib','fileutil')
4
+
5
+ unless ARGV[0] and ARGV[1] and ARGV[2]
6
+ puts "Usage: substitute <path> <old_content> <new_content>"
7
+ puts "Example: substitute mydir/ hello hey"
8
+ exit
9
+ end
10
+ unless File.exist? ARGV[0]
11
+ puts "#{ARGV[0]} does not exist."
12
+ puts "Please provide the path to the file or directory you want to manipulate."
13
+ exit
14
+ end
15
+
16
+ path=ARGV[0]
17
+ @old_content=ARGV[1]
18
+ @new_content=ARGV[2]
19
+
20
+ def file_substitute file_path
21
+ success=Rubisc::FileUtil::process_file(file_path) do |content|
22
+ pattern=content.match /#{@old_content}/
23
+ if !pattern
24
+ puts "No matching found."
25
+ end
26
+ content=content.gsub /#{@old_content}/,@new_content
27
+ end
28
+ if !success
29
+ puts 'Failed to process file '+file_path+'.'
30
+ end
31
+ end
32
+
33
+ def dir_substitute path
34
+ if path!="." and path!=".."
35
+ if File.directory?(path)
36
+ Dir.entries(path).each do |sub|
37
+ if sub!="." and sub!=".."
38
+ dir_substitute "#{path}/#{sub}"
39
+ end
40
+ end
41
+ else
42
+ file_substitute path
43
+ end
44
+ end
45
+ end
46
+
47
+ dir_substitute path
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby
2
+ module Rubisc
3
+ module FileUtil
4
+ def self.process_file file_path
5
+ return true unless block_given?
6
+ if !File.file? file_path
7
+ puts "Not a file: "+file_path
8
+ return false
9
+ end
10
+ file=File.new file_path,"r"
11
+ if !file
12
+ puts "Failed to read file "+file_path
13
+ return false
14
+ end
15
+ content=""
16
+ file.each do |line|
17
+ content<<line
18
+ end
19
+ content=yield content
20
+ file.close
21
+ file=File.new file_path,"w"
22
+ if !file
23
+ puts "Failed to write file "+file_path
24
+ return false
25
+ end
26
+ file.write content
27
+ file.close
28
+ return true
29
+ end
30
+ end
31
+ end
data/lib/rubisc.rb ADDED
@@ -0,0 +1 @@
1
+ puts 'Wicked cool ruby scripts!'
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubisc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - luqyluqe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Wicked cool ruby scripts
14
+ email: luqy.luqe@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/rubisc.rb
20
+ - lib/bin/substitute
21
+ - lib/lib/fileutil.rb
22
+ homepage: https://github.com/luqyluqe/Rubisc
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.14.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Wicked cool ruby scripts
46
+ test_files: []