class GrepLogic
Singleton class for cure grep Managing the method for matching and printing.
Public Class Methods
new()
click to toggle source
Calls superclass method
BaseLogic::new
# File lib/cureutils/logic/grep_logic.rb, line 14 def initialize super @match_method = 'match' end
Public Instance Methods
option_colorize(colorize)
click to toggle source
# File lib/cureutils/logic/grep_logic.rb, line 24 def option_colorize(colorize) @str_color = (colorize ? ColorMode::RED : ColorMode::NONE) end
option_only(only_flag)
click to toggle source
# File lib/cureutils/logic/grep_logic.rb, line 19 def option_only(only_flag) @only_matched = only_flag @match_method = (only_flag ? 'scan' : 'match') end
pattern(pat, is_exregex = false)
click to toggle source
# File lib/cureutils/logic/grep_logic.rb, line 28 def pattern(pat, is_exregex = false) if is_exregex @pattern = /#{pat}/ return end @pattern = /#{Common.pregex2regex(pat)}/ end
print_results()
click to toggle source
# File lib/cureutils/logic/grep_logic.rb, line 36 def print_results exit_status = 1 @in.each do |line| matched_strs = line.send(@match_method, @pattern) next unless matched_strs exit_status = 0 if @only_matched matched_strs.each { |str| @out.puts str.send(@str_color) } else @out.puts line.gsub(@pattern, '\0'.send(@str_color)) end end exit_status end