-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.rb
50 lines (41 loc) · 962 Bytes
/
common.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'csv'
require 'awesome_print'
#require 'mysql'
require 'pp'
require 'facets/kernel/blank'
require 'sqlite3'
def show_me!
transform do |row|
ap row
row # always return the row to keep it in the pipeline
end
end
class CsvSource
def initialize(file, options)
@file = file
@options = options
end
def each
CSV.foreach(@file, @options) do |row|
yield row.to_hash
end
end
end
class VerifyFieldsPresence
def initialize(expected_fields)
@expected_fields = expected_fields
end
def process(row)
@expected_fields.each do |field|
begin
if row[field].blank?
row = nil # raise "Row lacks value for field #{field} - #{row.inspect}"
end
rescue Exception => e
puts "Field not present"
break
end
end
row
end
end