Class: StringsFromApk::Resource

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

Overview

load apk

Constant Summary collapse

@@jar =
File.expand_path '../' * 3 + 'strings_from_apk.jar', __FILE__

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apk_path, locale = nil) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/strings_from_apk/resource.rb', line 7

def initialize apk_path, locale=nil
  json_folder = Dir::Tmpname.make_tmpname '/tmp/', nil
  json_file = File.join json_folder, 'strings.json'
  cmd = %Q(java -jar "#{@@jar}" "#{apk_path}" "#{json_folder}")
  cmd = cmd + %Q( "#{locale}") if locale
  `#{cmd}`
  @json = JSON.parse(File.read(json_file), max_nesting: 9999)

  # Remove the tmp folder after parsing.
  FileUtils.rm_rf json_folder
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



5
6
7
# File 'lib/strings_from_apk/resource.rb', line 5

def json
  @json
end

Instance Method Details

#get_string(string) ⇒ Object



19
20
21
# File 'lib/strings_from_apk/resource.rb', line 19

def get_string string
  @json[string]
end