Class: PinkShirt::Output
- Inherits:
-
Object
- Object
- PinkShirt::Output
- Defined in:
- lib/pink_shirt/output.rb
Overview
Nokogiri::Sax builds output as a long stream. Output collects all the writes as an array, and then joins them when required you can also lock it for writing.
Usage
stream = Output.new
stream << 'goods... '
stream.inspect #=> ['goods... ']
stream.lock('suspicious tag')
stream << 'bad stuff'
stream.inspect #=> ['goods... ']
stream.unlock
stream << 'good again'
stream.inspect #=> ['goods... ', 'good again']
Instance Method Summary collapse
- #<<(more) ⇒ Object
-
#initialize ⇒ Output
constructor
A new instance of Output.
- #inspect ⇒ Object
- #join ⇒ Object
- #lock(key) ⇒ Object
- #sanitize ⇒ Object
- #to_s ⇒ Object
- #trim ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Output
Returns a new instance of Output.
22 23 24 25 26 27 |
# File 'lib/pink_shirt/output.rb', line 22 def initialize @contents = [] @silenced = false @locks = [] @ouput = "" end |
Instance Method Details
#<<(more) ⇒ Object
39 40 41 |
# File 'lib/pink_shirt/output.rb', line 39 def << (more) @contents << more unless @silenced end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/pink_shirt/output.rb', line 62 def inspect @contents end |
#join ⇒ Object
43 44 45 |
# File 'lib/pink_shirt/output.rb', line 43 def join @output = @contents.join end |
#lock(key) ⇒ Object
29 30 31 32 |
# File 'lib/pink_shirt/output.rb', line 29 def lock(key) @locks << key @silenced = true end |
#sanitize ⇒ Object
47 48 49 |
# File 'lib/pink_shirt/output.rb', line 47 def sanitize @output = PinkShirt::Entities.sanitize(@output) end |
#to_s ⇒ Object
55 56 57 58 59 60 |
# File 'lib/pink_shirt/output.rb', line 55 def to_s join sanitize trim @output end |
#trim ⇒ Object
51 52 53 |
# File 'lib/pink_shirt/output.rb', line 51 def trim @output = @output.chomp.chomp.chomp end |
#unlock ⇒ Object
34 35 36 37 |
# File 'lib/pink_shirt/output.rb', line 34 def unlock @locks.pop @silenced = false if @locks.empty? end |