Prefer it over named block parameters
Where the subject is clear from the call site. Names stay on
multi-line bodies, nested blocks, and multi-argument blocks.
Assisted-by: GLM-5.3 via pi
diff --git a/Rakefile b/Rakefile
index 4e7901a..2f0e1e5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -6,7 +6,7 @@ require "minitest/test_task"
Minitest::TestTask.create
-Dir.glob("tasks/*.rake").sort.each { |path| import path }
+Dir.glob("tasks/*.rake").sort.each { import it }
desc "Start development server, reloading on changes"
task :dev do
@@ -54,7 +54,7 @@ namespace :profile do
if identifiers.empty?
puts "No pro-tacts profiles found; remove by hand in System Settings → Profiles if one lingers."
else
- identifiers.each { |identifier| sh "profiles", "remove", "-identifier", identifier }
+ identifiers.each { sh "profiles", "remove", "-identifier", it }
end
end
end
diff --git a/lib/pro_tacts/vcard.rb b/lib/pro_tacts/vcard.rb
index c205abe..365f2ec 100644
--- a/lib/pro_tacts/vcard.rb
+++ b/lib/pro_tacts/vcard.rb
@@ -27,7 +27,7 @@ module ProTacts
module_function
def render(contact, uid:)
- name = contact.children.find { |node| node.name == "name" }
+ name = contact.children.find { it.name == "name" }
raise ArgumentError, "contact requires a name" unless name
lines = [
@@ -52,10 +52,10 @@ module ProTacts
# every missing component renders empty.
def structured_name(name)
overrides = name.children
- .select { |child| NAME_COMPONENTS.include?(child.name) }
- .to_h { |child| [child.name, string_argument(child)] }
+ .select { NAME_COMPONENTS.include?(it.name) }
+ .to_h { [it.name, string_argument(it)] }
- return components(NAME_COMPONENTS.map { |component| overrides.fetch(component, "") }) unless overrides.empty?
+ return components(NAME_COMPONENTS.map { overrides.fetch(it, "") }) unless overrides.empty?
display = display_name(name)
tokens = display.split
@@ -65,7 +65,7 @@ module ProTacts
end
def typed_property_lines(contact, kdl_name, vcard_name)
- contact.children.select { |node| node.name == kdl_name }.map do |node|
+ contact.children.select { it.name == kdl_name }.map do |node|
type = node.properties["type"]&.value
prefix = type ? "#{vcard_name};TYPE=#{type}" : vcard_name
"#{prefix}:#{escape(string_argument(node))}"
@@ -76,12 +76,12 @@ module ProTacts
# locality, region, postal code, country. The first two have no KDL
# counterpart and stay empty.
def address_lines(contact)
- contact.children.select { |node| node.name == "address" }.map do |node|
+ contact.children.select { it.name == "address" }.map do |node|
parts = node.children
- .select { |child| ADDRESS_PARTS.include?(child.name) }
- .to_h { |child| [child.name, string_argument(child)] }
+ .select { ADDRESS_PARTS.include?(it.name) }
+ .to_h { [it.name, string_argument(it)] }
- components = ["", "", *ADDRESS_PARTS.map { |part| parts.fetch(part, "") }]
+ components = ["", "", *ADDRESS_PARTS.map { parts.fetch(it, "") }]
type = node.properties["type"]&.value
prefix = type ? "ADR;TYPE=#{type}" : "ADR"
"#{prefix}:#{components(components)}"
@@ -93,12 +93,12 @@ module ProTacts
# normalized to the `\n` escape because a raw line break would end
# the property line.
def escape(text)
- text.gsub(/\r\n|\r/, "\n").gsub(/[\\;,\n]/) { |char| TEXT_ESCAPES.fetch(char) }
+ text.gsub(/\r\n|\r/, "\n").gsub(/[\\;,\n]/) { TEXT_ESCAPES.fetch(it) }
end
# Escapes each component, then joins with the component separator.
def components(values)
- values.map { |value| escape(value) }.join(";")
+ values.map { escape(it) }.join(";")
end
# Folds a logical line into physical lines of at most LINE_LIMIT
diff --git a/test/pro_tacts/test_vcard.rb b/test/pro_tacts/test_vcard.rb
index de8d354..55a8d1e 100644
--- a/test/pro_tacts/test_vcard.rb
+++ b/test/pro_tacts/test_vcard.rb
@@ -109,10 +109,10 @@ class VCardTest < Minitest::Test
physical = vcard.split("\r\n")
assert_operator physical.length, :>, 1, "expected folding"
- physical.each { |line| assert_operator line.bytesize, :<=, 75 }
+ physical.each { assert_operator it.bytesize, :<=, 75 }
logical = unfold(physical)
- assert_equal "FN:#{"x" * 30}#{("é" * 60)}", logical.find { |l| l.start_with?("FN:") }
+ assert_equal "FN:#{"x" * 30}#{("é" * 60)}", logical.find { it.start_with?("FN:") }
end
def test_properties_without_type
@@ -224,7 +224,7 @@ class VCardTest < Minitest::Test
def unfold(lines)
lines.slice_when { |_line, next_line| !next_line.start_with?(" ") }
- .map { |group| group.first + group.drop(1).map { |line| line[1..] }.join }
+ .map { |group| group.first + group.drop(1).map { it[1..] }.join }
end
# Reverses RFC 2426 section 2.4.2 escaping.
@@ -264,12 +264,12 @@ class VCardTest < Minitest::Test
logical_lines(vcard).each do |line|
head, value = line.split(":", 2)
name, raw_params = head.split(";", 2)
- type = raw_params&.then { |params| params[/\ATYPE=(.*)\z/, 1] }
+ type = raw_params&.then { it[/\ATYPE=(.*)\z/, 1] }
case name
when "FN" then fields[:fn] = unescape(value)
when "UID" then fields[:uid] = unescape(value)
when "N", "ADR"
- components = split_unescaped(value, ";").map { |part| unescape(part) }
+ components = split_unescaped(value, ";").map { unescape(it) }
fields[:n] = components if name == "N"
fields[:adr] << [components, type] if name == "ADR"
when "TEL" then fields[:tel] << [unescape(value), type]
@@ -298,7 +298,7 @@ class VCardTest < Minitest::Test
if name_children.empty?
contact << " name #{kdl_string(display)}\n"
else
- contact << " name #{kdl_string(display)} {\n#{name_children.map { |c| " #{c}\n" }.join} }\n"
+ contact << " name #{kdl_string(display)} {\n#{name_children.map { " #{it}\n" }.join} }\n"
end
phones.each do |value, type|
suffix = type ? " type=\"#{type}\"" : ""
@@ -339,7 +339,7 @@ class VCardTest < Minitest::Test
)
physical = vcard.split("\r\n")
- too_long = physical.find { |line| line.bytesize > 75 }
+ too_long = physical.find { it.bytesize > 75 }
raise "line exceeds 75 octets: #{too_long&.bytesize}" if too_long
raise "folded away the terminators" unless physical.first == "BEGIN:VCARD" && physical.last == "END:VCARD"
raise "UID did not survive folding" unless parse_vcard(vcard).fetch(:uid) == normalize(uid)
@@ -386,7 +386,7 @@ class VCardTest < Minitest::Test
expected_n = if components.values.none?
derived_n(display)
else
- %i[family given additional prefix suffix].map { |part| normalize(components.fetch(part) || "") }
+ %i[family given additional prefix suffix].map { normalize(components.fetch(it) || "") }
end
raise "N mismatch" unless parsed.fetch(:n) == expected_n