class PhraseApp::Android::FormatCheck
Attributes
keys[RW]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
PhraseApp::Android::PhraseAppClient::new
# File lib/phraseapp_android/format_check.rb, line 7 def initialize(options = {}) super(options) self.keys = xml_strings_to_hash 'strings', nil end
Public Instance Methods
perform()
click to toggle source
# File lib/phraseapp_android/format_check.rb, line 13 def perform count = locales.map { |l| perform_for_locale(l) }.reduce(:+) puts 'All texts are ok.'.green count end
perform_for_locale(locale)
click to toggle source
# File lib/phraseapp_android/format_check.rb, line 19 def perform_for_locale(locale) data = xml_strings_to_hash 'strings', locale count = 0 keys.each do |name, value| formatters = value.scan /(%[\d$a-z]+)/i count += 1 if formatters && !check_formatters(locale, data, name, formatters) end count end
Private Instance Methods
check_formatters(locale, locale_data, name, sample_formatters)
click to toggle source
# File lib/phraseapp_android/format_check.rb, line 41 def check_formatters(locale, locale_data, name, sample_formatters) localized_key = locale_data[name] if localized_key sw_formatters = localized_key.scan /(%[\d$a-z]+)/i if sample_formatters.sort != sw_formatters.sort puts ('%s: Arguments mismatch for %s' % [locale, name]).red return false end end true end
xml_strings_to_hash(file_name, locale)
click to toggle source
# File lib/phraseapp_android/format_check.rb, line 33 def xml_strings_to_hash(file_name, locale) string_keys = {} read_locale_file(file_name, locale).at('//resources').search('string').each do |string| string_keys[string.attr('name')] = string.text end string_keys end