Class: Init

Inherits:
Object
  • Object
show all
Defined in:
lib/transync/sync/init.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Init

Returns a new instance of Init.



8
9
10
11
12
# File 'lib/transync/sync/init.rb', line 8

def initialize(path)
  @path = path
  @config = GdocTrans::CONFIG
  @gdoc_access = @config['GDOC']
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/transync/sync/init.rb', line 6

def config
  @config
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/transync/sync/init.rb', line 6

def path
  @path
end

Instance Method Details

#runObject



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
# File 'lib/transync/sync/init.rb', line 14

def run
  # first we want to add all the files to spreadsheet as worksheets (tabs)
  # add_worksheet(title, max_rows = 100, max_cols = 20)
  session = GoogleDrive.(@gdoc_access['email'], @gdoc_access['password'])
  spreadsheet = session.spreadsheet_by_key(@gdoc_access['key'])

  @config['FILES'].each do |file|
    worksheet = spreadsheet.worksheets.select { |s| s.title == file }.first
    if worksheet.nil?
      worksheet = spreadsheet.add_worksheet(file)
      p "Adding #{file} worksheet to spreadsheet with first row (key and languages)"
    end

    worksheet[1, 1] = 'Key'
    @config['LANGUAGES'].each_with_index do |language, index|
      worksheet[1, index + 2] = language.upcase
    end
    worksheet.save
  end

  # now sync all our keys and translations to gdoc
  # this won't work if local files are not 'clean'.
  # to make them clean run test and update first!
  x2g = Xliff2GdocMain.new(path)
  x2g.run
end