Class: PhraseApp::Android::FormatCheck

Inherits:
PhraseAppClient show all
Defined in:
lib/phraseapp_android/format_check.rb

Instance Attribute Summary collapse

Attributes inherited from PhraseAppClient

#client, #locale_files, #locales, #project_id, #sub_path

Instance Method Summary collapse

Methods inherited from PhraseAppClient

#locale_file_name, #read_locale_file, #read_xml_file

Constructor Details

#initialize(options = {}) ⇒ FormatCheck

Returns a new instance of FormatCheck.



7
8
9
10
11
# File 'lib/phraseapp_android/format_check.rb', line 7

def initialize(options = {})
  super(options)

  self.keys = xml_strings_to_hash 'strings', nil
end

Instance Attribute Details

#keysObject

Returns the value of attribute keys.



5
6
7
# File 'lib/phraseapp_android/format_check.rb', line 5

def keys
  @keys
end

Instance Method Details

#performObject



13
14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# 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