Sha256: 7650b4c86d0b17efe3b1603e950212197274548ce0a05071e1a6595eb5f331af
Contents?: true
Size: 637 Bytes
Versions: 3
Compression:
Stored size: 637 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 = options[:fields].empty? ? [] : 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.2.9 | lib/hirb/helpers/object_table.rb |
hirb-0.2.8 | lib/hirb/helpers/object_table.rb |
hirb-0.2.7 | lib/hirb/helpers/object_table.rb |