Land #1681, @sempervictus Rex::Text::Ui::Table [] method

bug/bundler_fix
jvazquez-r7 2013-11-19 16:30:09 -06:00
commit 647c867c2d
No known key found for this signature in database
GPG Key ID: 38D99152B9352D83
1 changed files with 25 additions and 0 deletions

View File

@ -212,6 +212,31 @@ class Table
rows << '__hr__' rows << '__hr__'
end 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 alias p print
attr_accessor :header, :headeri # :nodoc: attr_accessor :header, :headeri # :nodoc: