class Bogo::Ui::Table

Table output helper

Attributes

proxy_to[R]

@return [Object]

table[R]

@return [Array<Proc>]

ui[R]

@return [Bogo::Ui]

Public Class Methods

new(ui, inst=nil, &block) click to toggle source

Create a new instance

@param ui [Bogo::Ui] @yield table content @return [self]

# 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

Public Instance Methods

display() click to toggle source

Output table to defined UI

@return [self] @note can be called multiple times to print table updates

# 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
method_missing(m_name, *args, &block) click to toggle source

If proxy instance is provided, forward if possible

Calls superclass method
# 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
row(options={}) { || ... } click to toggle source

Override to provide buffered support

@param options [Hash] @return [self]

# File lib/bogo/ui/table.rb, line 64
def row(options={})
  options[:encoding] ||= @table.encoding
  @row = BufferedRow.new(options.merge(:buffer => @table.buffer))
  yield
  @table.add(@row)
  self
end
update(&block) click to toggle source

Update the table content

@yield table content @return [self]

# File lib/bogo/ui/table.rb, line 44
def update(&block)
  @content << block
  self
end