Class: HTTPDisk::Grep::HeaderPrinter

Inherits:
Printer
  • Object
show all
Defined in:
lib/httpdisk/grep/printer.rb

Overview

header, then each match

Constant Summary

Constants inherited from Printer

Printer::GREP_COLOR

Instance Attribute Summary collapse

Attributes inherited from Printer

#output

Instance Method Summary collapse

Constructor Details

#initialize(output, head) ⇒ HeaderPrinter

Returns a new instance of HeaderPrinter.



60
61
62
63
64
# File 'lib/httpdisk/grep/printer.rb', line 60

def initialize(output, head)
  super(output)
  @head = head
  @printed = 0
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



58
59
60
# File 'lib/httpdisk/grep/printer.rb', line 58

def head
  @head
end

#printedObject (readonly)

Returns the value of attribute printed.



58
59
60
# File 'lib/httpdisk/grep/printer.rb', line 58

def printed
  @printed
end

Instance Method Details



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/httpdisk/grep/printer.rb', line 66

def print(path, payload, all_matches)
  # separator & filename
  output.puts if (@printed += 1) > 1
  output.puts path

  # --head
  if head
    io = StringIO.new
    payload.write_header(io)
    io.string.lines.each { output.puts "< #{_1}" }
  end

  # matches
  all_matches.each { print_matches(_1) }
end