Class: StringsUpdater

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

Instance Method Summary collapse

Instance Method Details

#get_plist_with_document_id(document_id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/StringsUpdater.rb', line 25

def get_plist_with_document_id(document_id)

  read_settings

  session = GoogleDrive.(@user_name, @user_password)
  @ws = session.spreadsheet_by_key(document_id).worksheets[0]

  plist = "\nFile generated Strings Updater v0.1\nMore info: https://github.com/artur-gurgul/strings_updater\n\n\n"
  i = 2
  while true


    break if @ws[i, 1] == "."

    plist += "\n//#{@ws[i, 1]}\n\n" if @ws[i, 1] != ""

    plist += "\"#{@ws[i, 2]}\" = \"#{@ws[i, 3]};\n" if @ws[i, 2] != ""
    i += 1
  end
  plist
end

#push_project(project_url, output_path, spread_id, branch_name) ⇒ Object



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
# File 'lib/StringsUpdater.rb', line 47

def push_project(project_url,output_path,spread_id, branch_name)
  Dir.chdir working_dictionary

  puts "cloning..."
  `git clone #{project_url} #{temp_catalog_name}`
  exit(-1) if $?.exitstatus != 0

  proj_path = working_dictionary + temp_catalog_name
  Dir.chdir proj_path

  puts "downloading google document..."
  plist = get_plist_with_document_id(spread_id)

  f = File.new(output_path, "w")
  f.write(plist)
  f.close

  puts "commitintg changes ...."
  `git commit -a -m "update translations"`
  `git push origin #{branch_name}`
  exit(-1) if $?.exitstatus != 0

  puts "cleaning ..."
  Dir.chdir working_dictionary
  `rm -rf #{proj_path}`
  puts "DONE"
end

#read_settingsObject



18
19
20
21
22
23
# File 'lib/StringsUpdater.rb', line 18

def read_settings
  config = IniFile.load "#{Dir.home}/.aplist/cred.cfg", :parameter => ":", :comment => ';'

  @user_name = config["user"]["login"]
  @user_password = config["user"]["password"]
end

#temp_catalog_nameObject



14
15
16
# File 'lib/StringsUpdater.rb', line 14

def temp_catalog_name
  "temp_proj"
end

#working_dictionaryObject



10
11
12
# File 'lib/StringsUpdater.rb', line 10

def working_dictionary
  "./"
end