Class: Ethel::Sources::CSV
Instance Method Summary
collapse
#all, #field_names, #fields
Constructor Details
#initialize(options = {}) ⇒ CSV
Returns a new instance of CSV.
4
5
6
7
8
9
10
|
# File 'lib/ethel/sources/csv.rb', line 4
def initialize(options = {})
if options[:string]
@data = ::CSV.parse(options[:string], :headers => true)
elsif options[:file]
@data = ::CSV.read(options[:file], :headers => true)
end
end
|
Instance Method Details
#each ⇒ Object
22
23
24
25
26
|
# File 'lib/ethel/sources/csv.rb', line 22
def each
@data.each do |row|
yield row.to_hash
end
end
|
#schema ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/ethel/sources/csv.rb', line 12
def schema
if @schema.nil?
@schema = []
@data..each do |name|
@schema << [name, {:type => :string}]
end
end
@schema
end
|