lib/bisu/google_sheet.rb in bisu-1.3.0 vs lib/bisu/google_sheet.rb in bisu-1.3.1
- old
+ new
@@ -6,26 +6,26 @@
def initialize(sheet_id, keys_column_title)
@sheet_id = sheet_id
@key_column = keys_column_title
end
- def to_h
+ def to_i18
raw = raw_data(@sheet_id)
Logger.info("Parsing Google Sheet...")
- remove = ["id", "updated", "category", "title", "content", "link", @key_column]
+ non_language_columns = ["id", "updated", "category", "title", "content", "link", @key_column]
kb = {}
raw["entry"].each do |entry|
- hash = entry.select { |d| !remove.include?(d) }
- hash = hash.each.map { |k, v| v.first == {} ? [k, nil] : [k, v.first] }
-
unless (key = entry[@key_column]) && key = key.first
raise "Cannot find key column '#{@key_column}'"
end
- kb[key] = Hash[hash]
+ entry.select { |c| !non_language_columns.include?(c) }.each do |lang, texts|
+ kb[lang] ||= {}
+ kb[lang][key] = texts.first unless texts.first == {}
+ end
end
Logger.info("Google Sheet parsed successfully!")
Logger.info("Found #{kb.count} keys in #{kb.values.first.keys.count} languages.")