Class: Bstat2google::GoogleTarget

Inherits:
Target
  • Object
show all
Defined in:
lib/bstat2google.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ GoogleTarget

Returns a new instance of GoogleTarget.



69
70
71
# File 'lib/bstat2google.rb', line 69

def initialize(attrs = {})
  attrs.each {|k,v| self.send("#{k}=", v)}
end

Instance Attribute Details

#colObject

Returns the value of attribute col.



68
69
70
# File 'lib/bstat2google.rb', line 68

def col
  @col
end

#gmailObject

Returns the value of attribute gmail.



68
69
70
# File 'lib/bstat2google.rb', line 68

def gmail
  @gmail
end

#mapped_colsObject

Returns the value of attribute mapped_cols.



68
69
70
# File 'lib/bstat2google.rb', line 68

def mapped_cols
  @mapped_cols
end

#passwordObject

Returns the value of attribute password.



68
69
70
# File 'lib/bstat2google.rb', line 68

def password
  @password
end

#rowObject

Returns the value of attribute row.



68
69
70
# File 'lib/bstat2google.rb', line 68

def row
  @row
end

#sheet_idObject

Returns the value of attribute sheet_id.



68
69
70
# File 'lib/bstat2google.rb', line 68

def sheet_id
  @sheet_id
end

#timestamp_cellObject

Returns the value of attribute timestamp_cell.



68
69
70
# File 'lib/bstat2google.rb', line 68

def timestamp_cell
  @timestamp_cell
end

#worksheet_noObject

Returns the value of attribute worksheet_no.



68
69
70
# File 'lib/bstat2google.rb', line 68

def worksheet_no
  @worksheet_no
end

Instance Method Details

#write(bucket_stats) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bstat2google.rb', line 72

def write(bucket_stats)
  puts "-------------------------"
  puts "BucketId: #{bucket_stats.id}"
  puts "Error: #{bucket_stats.id}" if bucket_stats.error
  ap bucket_stats.kpis

  session = GoogleDrive.(gmail, password)
  ws = session.spreadsheet_by_key(sheet_id).worksheets[worksheet_no.to_i]

  if mapped_cols.first == "USE_CATEGORIES" 
    bucket_stats.kpis.keys.each_with_index do |kpi_value, i|
      ws[row.to_i, col.to_i+i] = kpi_value
    end
  else
    mapped_cols.each_with_index do |kpi_term, i|
      ws[row.to_i, col.to_i+i] = bucket_stats.kpis[kpi_term]
    end
  end
  ws[timestamp_cell] = Time.now.strftime("%d/%m/%y %H:%M")
  ws.save
end