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.



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

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

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



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

def head
  @head
end

#printedObject (readonly)

Returns the value of attribute printed.



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

def printed
  @printed
end

Instance Method Details



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

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