Module: Graphene::Tablize

Included in:
ResultSet
Defined in:
lib/graphene/tablizer.rb

Instance Method Summary collapse

Instance Method Details

#tablize(options = {}) ⇒ Object

Return the results formatted by the tablizer gem. Do disable headers, pass :header => false. Set alignment with :align.



4
5
6
7
8
9
10
11
12
13
# File 'lib/graphene/tablizer.rb', line 4

def tablize(options={})
  rows = to_a
  # Default to including headers
  unless options[:header] == false
    headers = attributes.map(&:to_s) << self.class.name.scan(/\w+$/).last.to_s.gsub(/s$/, '').capitalize
    rows.unshift(headers)
    options[:header] = true
  end
  Tablizer::Table.new(rows, options)
end