Skip to content

Commit 1fbd208

Browse files
committed
Quick local params/vars renaming + doc fixes
To clarify their purpose and type and help make sense of the code more easily.
1 parent ba4a46c commit 1fbd208

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ module Android
1111
module LocalizeHelper
1212
LIB_SOURCE_XML_ATTR = 'a8c-src-lib'.freeze
1313

14-
# Checks if string_line has the content_override flag set
15-
def self.skip_string_by_tag(string_line)
16-
skip = string_line.attr('content_override') == 'true' unless string_line.attr('content_override').nil?
14+
# Checks if `string_node` has the content_override flag set
15+
def self.skip_string_by_tag?(string_node)
16+
skip = string_node.attr('content_override') == 'true' unless string_node.attr('content_override').nil?
1717
if skip
18-
UI.message " - Skipping #{string_line.attr('name')} string"
18+
UI.message " - Skipping #{string_node.attr('name')} string"
1919
return true
2020
end
2121

2222
return false
2323
end
2424

25-
# Checks if string_name is in the excluesion list
26-
def self.skip_string_by_exclusion_list(library, string_name)
25+
# Checks if `string_name` is in the exclusion list
26+
def self.skip_string_by_exclusion_list?(library, string_name)
2727
return false if library[:exclusions].nil?
2828

2929
skip = library[:exclusions].include?(string_name)
@@ -43,66 +43,66 @@ def self.add_xml_attributes!(string_node, library)
4343
string_node[LIB_SOURCE_XML_ATTR] = library[:source_id] unless library[:source_id].nil?
4444
end
4545

46-
# Merge string_line into main_string
47-
def self.merge_string(main_strings, library, string_line)
48-
string_name = string_line.attr('name')
49-
string_content = string_line.content
46+
# Merge a single `lib_string_node` XML node into the `main_strings_xml``
47+
def self.merge_string_node(main_strings_xml, library, lib_string_node)
48+
string_name = lib_string_node.attr('name')
49+
string_content = lib_string_node.content
5050

5151
# Skip strings in the exclusions list
52-
return :skipped if skip_string_by_exclusion_list(library, string_name)
52+
return :skipped if skip_string_by_exclusion_list?(library, string_name)
5353

5454
# Search for the string in the main file
5555
result = :added
56-
main_strings.xpath('//string').each do |this_string|
57-
if this_string.attr('name') == string_name
56+
main_strings_xml.xpath('//string').each do |main_string_node|
57+
if main_string_node.attr('name') == string_name
5858
# Skip if the string has the content_override tag
59-
return :skipped if skip_string_by_tag(this_string)
59+
return :skipped if skip_string_by_tag?(main_string_node)
6060

6161
# If nodes are equivalent, skip
62-
return :found if string_line =~ this_string
62+
return :found if lib_string_node =~ main_string_node
6363

6464
# The string needs an update
6565
result = :updated
66-
if this_string.attr('tools:ignore').nil?
66+
if main_string_node.attr('tools:ignore').nil?
6767
# It can be updated, so remove the current one and move ahead
68-
this_string.remove
68+
main_string_node.remove
6969
break
7070
else
7171
# It has the tools:ignore flag, so update the content without touching the other attributes
72-
this_string.content = string_content
73-
add_xml_attributes!(this_string, library)
72+
main_string_node.content = string_content
73+
add_xml_attributes!(main_string_node, library)
7474
return result
7575
end
7676
end
7777
end
7878

7979
# String not found, or removed because needing update and not in the exclusion list: add to the main file
80-
add_xml_attributes!(string_line, library)
81-
main_strings.xpath('//string').last().add_next_sibling("\n#{' ' * 4}#{string_line.to_xml().strip}")
80+
add_xml_attributes!(lib_string_node, library)
81+
main_strings_xml.xpath('//string').last().add_next_sibling("\n#{' ' * 4}#{lib_string_node.to_xml().strip}")
8282
return result
8383
end
8484

85-
# Verify a string
86-
def self.verify_string(main_strings, library, string_line)
87-
string_name = string_line.attr('name')
88-
string_content = string_line.content
85+
# Verify a string node from a library has properly been merged into the main one
86+
def self.verify_string(main_strings_xml, library, lib_string_node)
87+
string_name = lib_string_node.attr('name')
88+
string_content = lib_string_node.content
8989

9090
# Skip strings in the exclusions list
91-
return if skip_string_by_exclusion_list(library, string_name)
91+
return if skip_string_by_exclusion_list?(library, string_name)
9292

9393
# Search for the string in the main file
94-
main_strings.xpath('//string').each do |this_string|
95-
if this_string.attr('name') == string_name
94+
main_strings_xml.xpath('//string').each do |main_string_node|
95+
if main_string_node.attr('name') == string_name
9696
# Skip if the string has the content_override tag
97-
return if skip_string_by_tag(this_string)
97+
return if skip_string_by_tag?(main_string_node)
9898

99-
# Update if needed
100-
UI.user_error!("String #{string_name} [#{string_content}] has been updated in the main file but not in the library #{library[:library]}.") if this_string.content != string_content
99+
# Check if up-to-date
100+
UI.user_error!("String #{string_name} [#{string_content}] has been updated in the main file but not in the library #{library[:library]}.") if main_string_node.content != string_content
101101
return
102102
end
103103
end
104104

105-
# String not found and not in the exclusion list:
105+
# String not found and not in the exclusion list
106106
UI.user_error!("String #{string_name} [#{string_content}] was found in library #{library[:library]} but not in the main file.")
107107
end
108108

@@ -122,23 +122,23 @@ def self.verify_string(main_strings, library, string_line)
122122
#
123123
def self.merge_lib(main, library)
124124
UI.message("Merging #{library[:library]} strings into #{main}")
125-
main_strings = File.open(main) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
126-
lib_strings = File.open(library[:strings_path]) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
125+
main_strings_xml = File.open(main) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
126+
lib_strings_xml = File.open(library[:strings_path]) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
127127

128128
updated_count = 0
129129
untouched_count = 0
130130
added_count = 0
131131
skipped_count = 0
132-
lib_strings.xpath('//string').each do |string_line|
133-
res = merge_string(main_strings, library, string_line)
132+
lib_strings_xml.xpath('//string').each do |string_node|
133+
res = merge_string_node(main_strings_xml, library, string_node)
134134
case res
135135
when :updated
136-
UI.verbose "#{string_line.attr('name')} updated."
136+
UI.verbose "#{string_node.attr('name')} updated."
137137
updated_count = updated_count + 1
138138
when :found
139139
untouched_count = untouched_count + 1
140140
when :added
141-
UI.verbose "#{string_line.attr('name')} added."
141+
UI.verbose "#{string_node.attr('name')} added."
142142
added_count = added_count + 1
143143
when :skipped
144144
skipped_count = skipped_count + 1
@@ -148,7 +148,7 @@ def self.merge_lib(main, library)
148148
end
149149

150150
File.open(main, 'w:UTF-8') do |f|
151-
f.write(main_strings.to_xml(indent: 4))
151+
f.write(main_strings_xml.to_xml(indent: 4))
152152
end
153153

154154
UI.message("Done (#{added_count} added, #{updated_count} updated, #{untouched_count} untouched, #{skipped_count} skipped).")
@@ -164,8 +164,8 @@ def self.verify_diff(diff_string, main_strings, lib_strings, library)
164164

165165
diff_string = diff_string.slice(0..(end_index - 1))
166166

167-
lib_strings.xpath('//string').each do |string_line|
168-
res = verify_string(main_strings, library, string_line) if string_line.attr('name') == diff_string
167+
lib_strings.xpath('//string').each do |string_node|
168+
res = verify_string(main_strings, library, string_node) if string_node.attr('name') == diff_string
169169
end
170170
end
171171
end

0 commit comments

Comments
 (0)