Module: SQLite3::Query::Description

Defined in:
lib/sqlite3/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



26
27
28
# File 'lib/sqlite3/query.rb', line 26

def columns
  @columns
end

Instance Method Details

#convert_record(record, cols) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sqlite3/query.rb', line 47

def convert_record(record, cols)
  values = cols.map do |col|
    id, type = col.values_at(:id, :type)
    v = record.send(id)

    case type
    when :date      then f = v.strftime("%a %b, %Y")
    when :datetime  then f = v.inspect
    when :number    then f = v
    else            f = v
    end


    { v: v, f: f }
  end

  { c: values }
end

#data_tableObject

A Google Chart compatible data table; see developers.google.com/chart/interactive/docs/reference#dataparam



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sqlite3/query.rb', line 30

def data_table
  cols = columns.map do |column|
    type = case column
    when /_at$/   then :datetime
    when /_on$/   then :date
    when /value/  then :number
    else               :string
    end

    { id: column, type: type, label: column }
  end

  rows = map { |record| convert_record record, cols }

  { cols: cols, rows: rows }
end