Class: FindGrep::FindGrep
- Inherits:
-
Object
- Object
- FindGrep::FindGrep
- Defined in:
- lib/gren/findgrep/findgrep.rb
Defined Under Namespace
Classes: Option
Instance Attribute Summary collapse
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(patterns, option) ⇒ FindGrep
constructor
A new instance of FindGrep.
- #searchAndPrint(stdout) ⇒ Object
- #strs2regs(strs) ⇒ Object
Constructor Details
#initialize(patterns, option) ⇒ FindGrep
Returns a new instance of FindGrep.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gren/findgrep/findgrep.rb', line 53 def initialize(patterns, option) @patterns = patterns @option = option @patternRegexps = strs2regs(patterns) @subRegexps = strs2regs(option.keywordsNot) @orRegexps = strs2regs(option.keywordsOr) @filePatterns = strs2regs(option.filePatterns) @ignoreFiles = strs2regs(option.ignoreFiles) @ignoreDirs = strs2regs(option.ignoreDirs) @result = Result.new(option.directory) require 'termcolor' if @option.colorHighlight end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
51 52 53 |
# File 'lib/gren/findgrep/findgrep.rb', line 51 def documents @documents end |
Class Method Details
.create_default_option ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gren/findgrep/findgrep.rb', line 32 def self.create_default_option Option.new([], [], ".", -1, false, false, false, false, false, [], [], [], [], Kconv::UTF8, # Platform.get_shell_kcode, false, false) end |
Instance Method Details
#searchAndPrint(stdout) ⇒ Object
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 |
# File 'lib/gren/findgrep/findgrep.rb', line 79 def searchAndPrint(stdout) unless Util.pipe?($stdin) searchFromDir(stdout, @option.directory, 0) else begin searchData(stdout, FindGrep::convline($stdin.read, @option.kcode).split($/), nil) rescue ArgumentError stdout.puts "invalid byte sequence : $stdin" end end @result.time_stop if !@option.isSilent if (@option.debugMode) stdout.puts stdout.puts "--- search --------" print_fpaths stdout, @result.search_files stdout.puts "--- match --------" print_fpaths stdout, @result.match_files stdout.puts "--- ignore-file --------" print_fpaths stdout, @result.ignore_files stdout.puts "--- ignore-dir --------" print_fpaths stdout, @result.prune_dirs stdout.puts "--- unreadable --------" print_fpaths stdout, @result.unreadable_files end unless (@option.colorHighlight) stdout.puts else stdout.puts HighLine::REVERSE + "------------------------------------------------------------" + HighLine::CLEAR end @result.print(stdout) end end |
#strs2regs(strs) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gren/findgrep/findgrep.rb', line 67 def strs2regs(strs) regs = [] strs.each do |v| option = 0 option |= Regexp::IGNORECASE if (@option.ignoreCase || (!@option.caseSensitive && Util::downcase?(v))) regs << Regexp.new(FindGrep::convline(v, @option.kcode), option) end regs end |