Class: RServiceBus::Monitor_CsvDir

Inherits:
Monitor_Dir show all
Defined in:
lib/rservicebus/Monitor/CsvDir.rb

Instance Attribute Summary

Attributes inherited from Monitor

#Bus

Instance Method Summary collapse

Methods inherited from Monitor_Dir

#Look, #ProcessPath, #ReadContentFromFile, #ReadContentFromGzFile, #ReadContentFromTarFile, #ReadContentFromZipFile, #connect

Methods inherited from Monitor

#Look, #_connect, #connect, #finished, #initialize, #reconnect, #send

Constructor Details

This class inherits a constructor from RServiceBus::Monitor

Instance Method Details

#checkPayloadForNumberOfColumns(payload) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rservicebus/Monitor/CsvDir.rb', line 9

def checkPayloadForNumberOfColumns( payload )
    return if @QueryStringParts.nil?
    return unless @QueryStringParts.has_key?('cols')
    
    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

#checkSendHashObject



22
23
24
25
26
27
28
29
# File 'lib/rservicebus/Monitor/CsvDir.rb', line 22

def checkSendHash
    if !@QueryStringParts.nil? && @QueryStringParts.has_key?('hash') then
        flag = @QueryStringParts['hash'][0]
        return flag == 'Y'
    end
    
    return false
end

#ProcessContent(content) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/rservicebus/Monitor/CsvDir.rb', line 46

def ProcessContent( content )
    payload = CSV.parse( content )
    self.checkPayloadForNumberOfColumns( payload )
    
    if self.checkSendHash then
        payload = self.ProcessToHash( payload )
    end

    return payload
end

#ProcessToHash(payload) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rservicebus/Monitor/CsvDir.rb', line 32

def ProcessToHash( payload )
    headLine = payload.shift
    newPayload = Array.new
    payload.each do |csvline|
        hash = Hash.new
        csvline.each_with_index do |v,idx|
            hash[headLine[idx]] = v
        end
        newPayload << hash
    end
    
    return newPayload
end