Class: XPGrep::CLI::UI
- Inherits:
-
Object
- Object
- XPGrep::CLI::UI
- Defined in:
- lib/xpgrep.rb
Instance Method Summary collapse
-
#initialize(file_count, out = STDOUT, err = STDERR) ⇒ UI
constructor
A new instance of UI.
-
#perror(exception, prefix = $0) ⇒ Object
Prints the error message from an exception, prefixed with the program name.
-
#print_match(fn, match) ⇒ Object
Prints a single matched node, possibly prefixed with the filename in which it occurs.
- #puts(*args) ⇒ Object
Constructor Details
#initialize(file_count, out = STDOUT, err = STDERR) ⇒ UI
Returns a new instance of UI.
39 40 41 42 |
# File 'lib/xpgrep.rb', line 39 def initialize(file_count, out = STDOUT, err = STDERR) @file_count = file_count @out, @err = out, err end |
Instance Method Details
#perror(exception, prefix = $0) ⇒ Object
Prints the error message from an exception, prefixed with the program name.
74 75 76 77 |
# File 'lib/xpgrep.rb', line 74 def perror(exception, prefix = $0) @err.print "#{prefix}: " if prefix @err.puts exception. end |
#print_match(fn, match) ⇒ Object
Prints a single matched node, possibly prefixed with the filename in which it occurs. If more than one file was given on the command line, or -H was passed, print it.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/xpgrep.rb', line 55 def print_match(fn, match) print_filename = Options.instance.print_filename if (@file_count > 1 and print_filename.nil?) or print_filename @out.print "#{fn}: " end if (attribute = Options.instance.attribute) @out.puts match[attribute] else @out.puts match end end |
#puts(*args) ⇒ Object
44 45 46 |
# File 'lib/xpgrep.rb', line 44 def puts(*args) @out.puts *args end |