Class: Bisu::Source::GoogleSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/bisu/source/google_sheet.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ GoogleSheet

Returns a new instance of GoogleSheet.



7
8
9
# File 'lib/bisu/source/google_sheet.rb', line 7

def initialize(url)
  @url = url
end

Instance Method Details

#to_i18Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bisu/source/google_sheet.rb', line 11

def to_i18
  Logger.info("Downloading Google Sheet from #{@url}...")

  csv = get_csv(@url)

  hash = {}

  languages = csv.headers[1..]
  languages.each { |lang| hash[lang] = {} }

  csv.each do |row|
    languages.each do |lang|
      hash[lang][row["key"]] = row[lang] unless row[lang].nil?
    end
  end

  Logger.info("Google Sheet parsed successfully!")
  Logger.info("Found #{languages.count} languages.")

  hash
end