Sha256: 3d578064a0fd8eedbb5e96c12ab54d6eec326a3f94d9f82b6660e92e3019aee4

Contents?: true

Size: 606 Bytes

Versions: 14

Compression:

Stored size: 606 Bytes

Contents

class Hirb::Helpers::ObjectTable < Hirb::Helpers::Table
  # Rows are any ruby objects. Takes same options as Hirb::Helpers::Table.render except as noted below.
  #
  # Options:
  #   :fields- Methods of the object to represent as columns. Defaults to [:to_s].
  def self.render(rows, options ={})
    options[:fields] ||= [:to_s]
    options[:headers] = {:to_s=>'value'} if options[:fields] == [:to_s]
    rows = [rows] unless rows.is_a?(Array)
    item_hashes = rows.inject([]) {|t,item|
      t << options[:fields].inject({}) {|h,f| h[f] = item.send(f); h}
    }
    super(item_hashes, options)
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
Chrononaut-hirb-0.2.1 lib/hirb/helpers/object_table.rb
Chrononaut-hirb-0.2.3 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.0 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.1 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.2 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.3 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.4 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.5 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.2.6 lib/hirb/helpers/object_table.rb
hirb-0.2.6 lib/hirb/helpers/object_table.rb
hirb-0.2.2 lib/hirb/helpers/object_table.rb
hirb-0.2.3 lib/hirb/helpers/object_table.rb
hirb-0.2.4 lib/hirb/helpers/object_table.rb
hirb-0.2.5 lib/hirb/helpers/object_table.rb