Module: Format

Included in:
CSVR::App
Defined in:
lib/csvr/format.rb

Class Method Summary collapse

Class Method Details

.headers(headers, types) ⇒ Object



6
7
8
9
# File 'lib/csvr/format.rb', line 6

def headers(headers, types)
  headers = headers.map { |h| "#{h} #{type(h, types)}" }.join(",")
  return headers
end

.row(row) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/csvr/format.rb', line 26

def row(row)
  if row.is_a? Hash
    values = row.values.map { |r| "'#{r}'"}.join(",")
    keys = row.keys.join(",")
  end
  return "(#{keys}) VALUES(#{values})"
end

.type(header, types) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/csvr/format.rb', line 11

def type(header, types)
  case types[header]
  when Fixnum
    return "INTEGER"
  when Float
    return "REAL"
  when nil
    return "NULL"
  when String
    return "TEXT"
  else
    return "TEXT"
  end
end