class Terrestrial::Cli::Parser::AndroidXML
Constants
- LANGUAGE
Public Class Methods
find_api_calls(file)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 11 def self.find_api_calls(file) self.new(file).find_api_calls end
find_strings(file)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 7 def self.find_strings(file) self.new(file).find_strings end
new(file)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 15 def initialize(file) @path = file @file = File.new(file) @document = REXML::Document.new(@file) end
Public Instance Methods
build_new_string_entry(node)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 37 def build_new_string_entry(node) Hash.new.tap do |entry| entry["language"] = LANGUAGE entry["file"] = @path entry["string"] = get_string_from_node(node) entry["type"] = "android-strings-xml" entry["line_number"] = nil # entry.variables = get_variables_from_string(entry.string) entry["identifier"] = node.attributes["name"] end end
build_registry_entry_hash(node)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 49 def build_registry_entry_hash(node) Hash.new.tap do |entry| entry["string"] = get_string_from_node(node) entry["context"] = node.attributes["context"] || "" entry["file"] = @path entry["line_number"] = nil entry["type"] = "android-strings-xml" entry["id"] = node.attributes["name"] end end
find_api_calls()
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 29 def find_api_calls result = [] REXML::XPath.each(@document, "//resources/string[@terrestrial=\"true\"]") do |node| result << build_registry_entry_hash(node) end result end
find_strings()
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 21 def find_strings result = [] REXML::XPath.each(@document, "//resources/string") do |node| result << build_new_string_entry(node) end result end
get_string_from_node(node)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 60 def get_string_from_node(node) # Why could the text be nil? # - If it contains valid XML! # # We assume anything inside the string tag is actually # what should be shown in the UI, so we just parse it # as a string if we realise that the parser thinks it # is XML. if !node.get_text.nil? node.get_text.value else node.children.first.to_s end end
get_variables_from_string(string)
click to toggle source
# File lib/terrestrial/cli/parser/android_xml.rb, line 76 def get_variables_from_string(string) string.scan(/(\%\d\$[dsf])/).map {|match| match[0] } end