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
23 24 25 26 27 28 29 |
# File 'lib/bogo/ui/table.rb', line 23 def initialize(ui, inst=nil, &block) @proxy_to = inst @ui = ui @base = block @content = [] @printed_lines = [] 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
32 33 34 35 36 37 38 |
# File 'lib/bogo/ui/table.rb', line 32 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)
16 17 18 |
# File 'lib/bogo/ui/table.rb', line 16 def proxy_to @proxy_to end |
#table(options = {}) ⇒ self (readonly)
Override to provide buffered support
14 15 16 |
# File 'lib/bogo/ui/table.rb', line 14 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 91 92 93 94 95 96 |
# 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 = output.find_all do |line| !@printed_lines.include?( Digest::SHA256.hexdigest(line.gsub(/\s/, '')) ) end @printed_lines.concat( output.map{|l| Digest::SHA256.hexdigest(l.gsub(/\s/, '')) } ) ui.puts output.join("\n") unless output.empty? 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
44 45 46 47 |
# File 'lib/bogo/ui/table.rb', line 44 def update(&block) @content << block self end |