Sha256: 40e9f0720abe8df72249201b71cb93e6cde47bce164bac7f0690b44bec3e38fc

Contents?: true

Size: 607 Bytes

Versions: 3

Compression:

Stored size: 607 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]
    item_hashes = options[:fields].empty? ? [] : Array(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

3 entries across 3 versions & 1 rubygems

Version Path
hirb-0.3.2 lib/hirb/helpers/object_table.rb
hirb-0.3.1 lib/hirb/helpers/object_table.rb
hirb-0.3.0 lib/hirb/helpers/object_table.rb