m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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