Class: Undies::NodeBuffer
- Inherits:
-
Array
- Object
- Array
- Undies::NodeBuffer
- Defined in:
- lib/undies/node_buffer.rb
Instance Method Summary collapse
- #flush(output) ⇒ Object
-
#initialize(*args) ⇒ NodeBuffer
constructor
the buffer allows for dynamic node handling while limiting memory bloat.
- #pull(output) ⇒ Object
- #push(node) ⇒ Object
Constructor Details
#initialize(*args) ⇒ NodeBuffer
the buffer allows for dynamic node handling while limiting memory bloat. the Output handler ensures that only 1 node is buffered in memory at any given time by pulling the previous node to output before pushing the next node for processing.
14 15 16 17 |
# File 'lib/undies/node_buffer.rb', line 14 def initialize(*args) # always initialize empty super() end |
Instance Method Details
#flush(output) ⇒ Object
30 31 32 |
# File 'lib/undies/node_buffer.rb', line 30 def flush(output) self.pull(output) while self.size > 0 end |
#pull(output) ⇒ Object
24 25 26 27 28 |
# File 'lib/undies/node_buffer.rb', line 24 def pull(output) if (node = self.shift) node.class.flush(output, node) end end |
#push(node) ⇒ Object
19 20 21 22 |
# File 'lib/undies/node_buffer.rb', line 19 def push(node) super node end |