Class: IO::CutInput

Inherits:
InputFilter show all
Defined in:
lib/ttk/Tools/cut_output.rb

Instance Method Summary collapse

Methods inherited from InputFilter

#each, #each_byte, #each_line, #getc, #gets, #read, #readlines

Methods inherited from IO

#compare_stream, dash, print_file, print_io, #testify, #to_diff_for_ttk_log, #to_s_for_ttk_log

Methods included from ImplIndent

#indent

Constructor Details

#initialize(io, lines = 10, column = 80) ⇒ CutInput

Returns a new instance of CutInput.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ttk/Tools/cut_output.rb', line 13

def initialize(io, lines=10, column=80)
  i = 0
  super(io) do |line|
	if @input.closed?
	  ''
	elsif i >= lines
	  @input.close
	  "...\n"
	else
	  i += 1
	  line.length <= column ? line : (line[0..column].chomp + "\n")
	end
  end
end