Class: Bogo::Ui::Table
- Inherits:
-
Object
- Object
- Bogo::Ui::Table
- Includes:
- CommandLineReporter
- Defined in:
- lib/bogo-ui/table.rb
Overview
Table output helper
Defined Under Namespace
Classes: BufferedRow, BufferedTable
Instance Attribute Summary collapse
- #proxy_to ⇒ Object readonly
-
#table(options = {}) ⇒ self
readonly
Override to provide buffered support.
- #ui ⇒ Bogo::Ui readonly
Instance Method Summary collapse
-
#display ⇒ self
Output table to defined UI.
-
#initialize(ui, inst = nil) { ... } ⇒ self
constructor
Create a new instance.
-
#method_missing(m_name, *args, &block) ⇒ Object
If proxy instance is provided, forward if possible.
-
#row(options = {}) ⇒ self
Override to provide buffered support.
-
#update { ... } ⇒ self
Update the table content.
Constructor Details
#initialize(ui, inst = nil) { ... } ⇒ self
Create a new instance
24 25 26 27 28 29 30 |
# File 'lib/bogo-ui/table.rb', line 24 def initialize(ui, inst=nil, &block) @proxy_to = inst @ui = ui @base = block @content = [] @printed_lines = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m_name, *args, &block) ⇒ Object
If proxy instance is provided, forward if possible
33 34 35 36 37 38 39 |
# File 'lib/bogo-ui/table.rb', line 33 def method_missing(m_name, *args, &block) if(proxy_to && proxy_to.respond_to?(m_name, true)) proxy_to.send(m_name, *args, &block) else super end end |
Instance Attribute Details
#proxy_to ⇒ Object (readonly)
17 18 19 |
# File 'lib/bogo-ui/table.rb', line 17 def proxy_to @proxy_to end |
#table(options = {}) ⇒ self (readonly)
Override to provide buffered support
15 16 17 |
# File 'lib/bogo-ui/table.rb', line 15 def table @table end |
Instance Method Details
#display ⇒ self
Note:
can be called multiple times to print table updates
Output table to defined UI
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bogo-ui/table.rb', line 76 def display # init the table instance_exec(&@base) # load the table @content.each do |tblock| instance_exec(&tblock) end @table.output @table.buffer.rewind output = @table.buffer.read.split("\n") output.slice!(0, @printed_lines) @printed_lines = output.size ui.puts output.join("\n") self end |
#row(options = {}) ⇒ self
Override to provide buffered support
64 65 66 67 68 69 70 |
# File 'lib/bogo-ui/table.rb', line 64 def row(={}) [:encoding] ||= @table.encoding @row = BufferedRow.new(.merge(:buffer => @table.buffer)) yield @table.add(@row) self end |
#update { ... } ⇒ self
Update the table content
45 46 47 48 |
# File 'lib/bogo-ui/table.rb', line 45 def update(&block) @content << block self end |