Class: Text::Sanitizer
- Inherits:
-
Object
- Object
- Text::Sanitizer
- Extended by:
- Forwardable
- Defined in:
- lib/text/sanitizer.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(output) ⇒ Sanitizer
constructor
A new instance of Sanitizer.
- #print(*args) ⇒ Object
Constructor Details
#initialize(output) ⇒ Sanitizer
Returns a new instance of Sanitizer.
13 14 15 16 |
# File 'lib/text/sanitizer.rb', line 13 def initialize(output) @output = output @current = "" end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/text/sanitizer.rb', line 8 def output @output end |
Instance Method Details
#flush ⇒ Object
30 31 32 33 34 35 |
# File 'lib/text/sanitizer.rb', line 30 def flush return if @current == "" clean = sanitize(@current) output.puts clean end |
#print(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/text/sanitizer.rb', line 18 def print(*args) @current << args.join loop do line, newline, rest = @current.partition("\n") break if newline != "\n" clean = sanitize(line) output.puts clean @current = rest end end |