m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib/util.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2023-01-26 12:15:59 +0100
committerMarcin Chrzanowski <m@m-chrzan.xyz>2023-01-26 12:15:59 +0100
commitfb42f4157c92eb35f54dd65425f1c7e6aca07389 (patch)
treed6caea2cfb75d55afae05c3484330cd670e138ee /lib/util.rb
parentaeacdaeb9607658bf9b101a5aaa4620181ccffe8 (diff)
Sort by Polish alphabet
Diffstat (limited to 'lib/util.rb')
-rw-r--r--lib/util.rb23
1 files changed, 23 insertions, 0 deletions
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