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



17
18
19
20
21
22
23
# File 'lib/csvr/format.rb', line 17

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
# File 'lib/csvr/format.rb', line 11

def type(header, types)
	return "TEXT" unless types[header] == Fixnum || types[header] == Float
	return "INTEGER" unless types[header] == Float
	return "REAL"
end