Sha256: 78bfa9642156fd8db673fe3fb1516ddb5af769de0f24769a7da6d6ab69105a8b

Contents?: true

Size: 666 Bytes

Versions: 4

Compression:

Stored size: 666 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 which are represented as columns in the table. Required option.
  #     All method values are converted to strings via to_s.
  def self.render(rows, options ={})
    raise(ArgumentError, "Option 'fields' is required.") unless options[:fields]
    rows = [rows] unless rows.is_a?(Array)
    item_hashes = rows.inject([]) {|t,item|
      t << options[:fields].inject({}) {|h,f| h[f] = item.send(f).to_s; h}
    }
    super(item_hashes, options)
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
cldwalker-hirb-0.1.0 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.1.1 lib/hirb/helpers/object_table.rb
cldwalker-hirb-0.1.2 lib/hirb/helpers/object_table.rb
hirb-0.1.2 lib/hirb/helpers/object_table.rb