Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#check_ignore_dir(filename) ⇒ Object

check dir if ignore



48
49
50
# File 'lib/replace_class.rb', line 48

def check_ignore_dir(filename)
	@ignore_dir.find_index(filename)
end

#check_valid_with_file(filename) ⇒ Object

check file if valid



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/replace_class.rb', line 53

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



76
77
78
79
80
81
82
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
# File 'lib/replace_class.rb', line 76

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/replace_class.rb', line 43

def hidden?(filename)
	filename =~ /^\./
end

#match?(line_or_filename) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/replace_class.rb', line 69

def match?(line_or_filename)
   
   regex = Regexp.new("([^a-zA-Z]|^)(#{@options[:source]})([^a-zA-Z]|$)")
   line_or_filename =~ regex
end