Land #1681, @sempervictus Rex::Text::Ui::Table [] method
commit
647c867c2d
|
@ -212,6 +212,31 @@ class Table
|
|||
rows << '__hr__'
|
||||
end
|
||||
|
||||
#
|
||||
# Returns new sub-table with headers and rows maching column names submitted
|
||||
#
|
||||
def [](*col_names)
|
||||
tbl = self.class.new('Indent' => self.indent,
|
||||
'Header' => self.header,
|
||||
'Columns' => col_names)
|
||||
indexes = []
|
||||
|
||||
col_names.each do |col_name|
|
||||
index = self.columns.index(col_name)
|
||||
raise RuntimeError, "Invalid column name #{col_name}" if index.nil?
|
||||
indexes << index
|
||||
end
|
||||
|
||||
self.rows.each do |old_row|
|
||||
new_row = []
|
||||
indexes.map {|i| new_row << old_row[i]}
|
||||
tbl << new_row
|
||||
end
|
||||
|
||||
return tbl
|
||||
end
|
||||
|
||||
|
||||
alias p print
|
||||
|
||||
attr_accessor :header, :headeri # :nodoc:
|
||||
|
|
Loading…
Reference in New Issue