Parent

Class/Module Index [+]

Quicksearch

Nanoc::CLI::CleaningStream

An output stream that passes output through stream cleaners. This can be used to strip ANSI color sequences, for instance.

Public Class Methods

new(stream) click to toggle source

@param [IO, StringIO] stream The stream to wrap

# File lib/nanoc/cli/cleaning_stream.rb, line 9
def initialize(stream)
  @stream = stream
  @stream_cleaners = []
end

Public Instance Methods

<<(s) click to toggle source

@see IO#<<

# File lib/nanoc/cli/cleaning_stream.rb, line 47
def <<(s)
  @stream.<<(self.clean(s))
end
add_stream_cleaner(klass) click to toggle source

Adds a stream cleaner for the given class to this cleaning stream. If the cleaning stream already has the given stream cleaner, nothing happens.

@param [Nanoc::CLI::StreamCleaners::Abstract] klass The class of the

stream cleaner to add

@return [void]

# File lib/nanoc/cli/cleaning_stream.rb, line 21
def add_stream_cleaner(klass)
  unless @stream_cleaners.map { |c| c.class }.include?(klass)
    @stream_cleaners << klass.new
  end
end
close() click to toggle source

@see IO#close

# File lib/nanoc/cli/cleaning_stream.rb, line 87
def close
  @stream.close
end
exist?() click to toggle source

@see File#exist?

# File lib/nanoc/cli/cleaning_stream.rb, line 92
def exist?
  @stream.exist?
end
exists?() click to toggle source

@see File.exists?

# File lib/nanoc/cli/cleaning_stream.rb, line 97
def exists?
  @stream.exists?
end
flush() click to toggle source

@see IO#flush

# File lib/nanoc/cli/cleaning_stream.rb, line 57
def flush
  @stream.flush
end
puts(*s) click to toggle source

@see IO#puts

# File lib/nanoc/cli/cleaning_stream.rb, line 72
def puts(*s)
  @stream.puts(*s.map { |ss| self.clean(ss) })
end
remove_stream_cleaner(klass) click to toggle source

Removes the stream cleaner for the given class from this cleaning stream. If the cleaning stream does not have the given stream cleaner, nothing happens.

@param [Nanoc::CLI::StreamCleaners::Abstract] klass The class of the

stream cleaner to add

@return [void]

# File lib/nanoc/cli/cleaning_stream.rb, line 35
def remove_stream_cleaner(klass)
  @stream_cleaners.delete_if { |c| c.class == klass }
end
reopen(*a) click to toggle source

@see IO#reopen

# File lib/nanoc/cli/cleaning_stream.rb, line 82
def reopen(*a)
  @stream.reopen(*a)
end
string() click to toggle source

@see StringIO#string

# File lib/nanoc/cli/cleaning_stream.rb, line 77
def string
  @stream.string
end
tell() click to toggle source

@see IO#tell

# File lib/nanoc/cli/cleaning_stream.rb, line 62
def tell
  @stream.tell
end
tty?() click to toggle source

@see IO#tty?

# File lib/nanoc/cli/cleaning_stream.rb, line 52
def tty?
  @cached_is_tty ||= @stream.tty?
end
winsize() click to toggle source

@see IO.winsize

# File lib/nanoc/cli/cleaning_stream.rb, line 102
def winsize
  @stream.winsize
end
winsize=(arg) click to toggle source

@see IO.winsize=

# File lib/nanoc/cli/cleaning_stream.rb, line 107
def winsize=(arg)
  @stream.winsize=(arg)
end
write(s) click to toggle source

@see IO#write

# File lib/nanoc/cli/cleaning_stream.rb, line 42
def write(s)
  @stream.write(self.clean(s))
end

Protected Instance Methods

clean(s) click to toggle source
# File lib/nanoc/cli/cleaning_stream.rb, line 113
def clean(s)
  @stream_cleaners.inject(s) { |m,c| c.clean(m) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.