From fb42f4157c92eb35f54dd65425f1c7e6aca07389 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 26 Jan 2023 12:15:59 +0100 Subject: Sort by Polish alphabet --- lib/util.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/util.rb b/lib/util.rb index 873b6f9..5509aad 100644 --- a/lib/util.rb +++ b/lib/util.rb @@ -87,3 +87,26 @@ end def path_to asset_id P.path_to asset_id end + +def normalize title + title.downcase.gsub /[[:punct:]]|[[:space:]]/, '' +end + +def indexify title + alphabet = "aąbcćdeęfghijklłmnńoóprsśtuwyzźż".chars + normalized = normalize title + normalized.chars.map do |c| + index = alphabet.find_index c + if index.nil? + raise "Letter not in alphabet: #{c}" + end + + index + end +end + +def polish_compare a, b + indices_a = indexify a + indices_b = indexify b + indices_a <=> indices_b +end -- cgit v1.2.3