Top Level Namespace
Instance Method Summary collapse
-
#check_ignore_dir(filename) ⇒ Object
check dir if ignore.
-
#check_valid_with_file(filename) ⇒ Object
check file if valid.
-
#checkDir(dir) ⇒ Object
main function.
-
#hidden?(filename) ⇒ Boolean
check file if hide.
- #match?(line_or_filename) ⇒ Boolean
Instance Method Details
#check_ignore_dir(filename) ⇒ Object
check dir if ignore
55 56 57 |
# File 'lib/replace_class.rb', line 55 def check_ignore_dir(filename) @ignore_dir.find_index(filename) end |
#check_valid_with_file(filename) ⇒ Object
check file if valid
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/replace_class.rb', line 60 def check_valid_with_file(filename) if filename !~ /^\./ then @valid_file_type.each do |ext| if File.extname(filename) == ext return true end end end false end |
#checkDir(dir) ⇒ Object
main function
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/replace_class.rb', line 83 def checkDir(dir) aDir = Dir.new(dir) aDir.each do |filename| filePath = File.join(dir, filename) isFile = File.file?(filePath) isDir = File.directory?(filePath) if isDir if !hidden?(filename) && !check_ignore_dir(filename) checkDir(filePath) end end if isFile if !check_valid_with_file(filename) next end if hidden?(filename) next end if match?(filename) puts "matching regex to file: #{filename}" end lines = IO.readlines(filePath) lines.each_index do |index| line = lines[index] if match?(line) puts "matching regex in line : [#{filename} : #{index + 1}] with content:\n#{line}" end end end end end |
#hidden?(filename) ⇒ Boolean
check file if hide
50 51 52 |
# File 'lib/replace_class.rb', line 50 def hidden?(filename) filename =~ /^\./ end |
#match?(line_or_filename) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/replace_class.rb', line 76 def match?(line_or_filename) regex = Regexp.new("([^a-zA-Z]|^)(#{@options[:source]})([^a-zA-Z]|$)") line_or_filename =~ regex end |