Method: GoogleSheetProcessor#initialize

Defined in:
lib/Processors/GoogleSheetProcessor.rb

#initialize(config, configFilePath, baseExecutePath) ⇒ GoogleSheetProcessor

Returns a new instance of GoogleSheetProcessor.



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/Processors/GoogleSheetProcessor.rb', line 13

def initialize(config, configFilePath, baseExecutePath)
    @config = config
    @configFilePath = configFilePath
    @baseExecutePath = baseExecutePath
    @logger = ZLogger.new(baseExecutePath)

    keyFilePath = Helper.unwrapRequiredParameter(config, "googleSheetAPIKeyFilePath")

    if Pathname.new(keyFilePath).absolute?
        configDir = File.dirname(configFilePath)
        keyFilePath = "#{configDir}#{keyFilePath}"
    end

    @googleAPI = GoogleAPI.new(keyFilePath, baseExecutePath, ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/spreadsheets"])

    @keywordsInclude = []
    if !config["keywordsInclude"].nil?
        @keywordsInclude = config["keywordsInclude"]
    end

    @ratingsInclude = []
    if !config["ratingsInclude"].nil?
        @ratingsInclude = config["ratingsInclude"]
    end

    @territoriesInclude = []
    if !config["territoriesInclude"].nil?
        @territoriesInclude = config["territoriesInclude"]
    end

    @timeZoneOffset = Helper.unwrapRequiredParameter(config, "googleSheetTimeZoneOffset")
    @spreadsheetID = Helper.unwrapRequiredParameter(config, "googleSpreadsheetID")
    
    sheetInsertStyle = Helper.unwrapRequiredParameter(config, "googleSheetInsertStyle")
    if !sheetInsertStyle.is_a? Array
        raise "googleSheetInsertStyle must specify as Array in GoogleSheetProcessor."
    end

    sheetInsertStyles = {}
    sheetInsertStyle.each do |value|
        value.keys.each do |key|
            sheetInsertStyles[key] = value[key]
        end
    end

    @sheetInsertType = Helper.unwrapRequiredParameter(sheetInsertStyles, "type")

    if sheetInsertType != "insert" && sheetInsertType != "append"
        raise "googleSheetInsertStyle.type only accept insert or append in GoogleSheetProcessor."
    elsif sheetInsertType == "insert"
        @sheetInsertAt = Helper.unwrapRequiredParameter(sheetInsertStyles, "at").to_i
        @sheetId = Helper.unwrapRequiredParameter(sheetInsertStyles, "sheetID")
    elsif sheetInsertType == "append"
        @sheetName = Helper.unwrapRequiredParameter(sheetInsertStyles, "sheetName")
    end
    
    @formatValues = []
    if !config["values"].nil?
        @formatValues = config["values"]
    end

    puts "[GoogleSheetProcessor] Init Success."
end