Class: RServiceBus::Monitor_CsvPerLineDir
Instance Attribute Summary
Attributes inherited from Monitor
#Bus
Instance Method Summary
collapse
Methods inherited from Monitor_Dir
#Look, #ProcessContent, #ReadContentFromFile, #ReadContentFromGzFile, #ReadContentFromTarFile, #ReadContentFromZipFile, #connect
Methods inherited from Monitor
#Look, #_connect, #connect, #finished, #initialize, #reconnect, #send
Instance Method Details
#checkPayloadForNumberOfColumns(payload) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/rservicebus/Monitor/CsvPerLine.rb', line 8
def checkPayloadForNumberOfColumns( payload )
if !@QueryStringParts.nil? && @QueryStringParts.has_key?('cols') then
cols = @QueryStringParts['cols'][0].to_i
payload.each_with_index do |row, idx|
if row.length != cols then
raise "Expected number of columns, #{cols}, Actual number of columns, #{row.length}, on line, #{idx}"
end
end
end
end
|
#checkSendHash ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/rservicebus/Monitor/CsvPerLine.rb', line 21
def checkSendHash
if !@QueryStringParts.nil? && @QueryStringParts.has_key?('hash') then
flag = @QueryStringParts['hash'][0]
return flag == 'Y'
end
return false
end
|
#ProcessPath(filePath) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rservicebus/Monitor/CsvPerLine.rb', line 48
def ProcessPath( filePath )
uri = URI.parse( "file://#{filePath}" )
content = IO.read( filePath )
payload = CSV.parse( content )
self.checkPayloadForNumberOfColumns( payload )
if self.checkSendHash then
self.SendHash( payload, uri )
else
self.SendArray( payload, uri )
end
return content
end
|
#SendArray(payload, uri) ⇒ Object
31
32
33
34
35
|
# File 'lib/rservicebus/Monitor/CsvPerLine.rb', line 31
def SendArray( payload, uri )
payload.each do |csvline|
self.send( csvline, uri )
end
end
|
#SendHash(payload, uri) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rservicebus/Monitor/CsvPerLine.rb', line 37
def SendHash( payload, uri )
headLine = payload.shift
payload.each do |csvline|
hash = Hash.new
csvline.each_with_index do |v,idx|
hash[headLine[idx]] = v
end
self.send( hash, uri )
end
end
|