class Expletive::Dump
Public Class Methods
new(in_io=$stdin, out_io=$stdout)
click to toggle source
# File lib/expletive/filters.rb, line 8 def initialize(in_io=$stdin, out_io=$stdout) @in = in_io @out = out_io @current_width = 0 end
Public Instance Methods
human_readable?(byte)
click to toggle source
# File lib/expletive/filters.rb, line 42 def human_readable?(byte) (byte >= SPACE) && (byte <= TILDE) end
run()
click to toggle source
# File lib/expletive/filters.rb, line 14 def run n = 0 until @in.eof? byte = @in.readbyte case when byte == BACKSLASH write_string "\\\\" when byte == NEWLINE write_string "\\n" when human_readable?(byte) write_string byte.chr else write_string "\\%02x" % byte end end end
start_new_line()
click to toggle source
# File lib/expletive/filters.rb, line 31 def start_new_line @out.print("\n") @current_width = 0 end
write_string(s)
click to toggle source
# File lib/expletive/filters.rb, line 36 def write_string(s) @out.print(s) @current_width += s.size start_new_line if @current_width > 60 end