ukrainian_sort 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf4a1519b5061ffa3b00fcc5a025233fc4a471f765bfd5ecde0171aca0615959
4
+ data.tar.gz: 01cbaf85442b91e9ed76303041af78e3367e517f5c714fe0e327cf2a56f3d34f
5
+ SHA512:
6
+ metadata.gz: a8b4fa753ebf07c7062cc5b60238b7aee0d4bdbe23827f4f3d21ad11fd478f23d10f19bfc064b34142d4fdf6ef3cc4330146788c594c0275af93126605539f39
7
+ data.tar.gz: 65071371b1d97351e846ecc59dddc0a4bffe8c5c9c267e867592307578dae67c169917b7f3e7e4e408e78c25f49926cfc533d1d4be0e1f74d04f548ccb103ab9
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](https://semver.org/) and [Keep a Changelog](https://keepachangelog.com/).
6
+
7
+ ---
8
+
9
+ ## [0.1.0] - 2025-07-18
10
+
11
+ ### Added
12
+ - Initial release.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 mykbren
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Ukrainian Sort Gem
2
+
3
+ ## Мотивація
4
+ Сортування українського тексту не працює у Ruby через стандартний механізм сортування, який базується на Unicode-кодах. Результат не відповідає порядку українського алфавіту.
5
+
6
+ Ця бібліотека забезпечує правильне сортування відповідно до українського алфавіту, вирішуючи проблеми, як-от розташування 'ґ' та 'є'.
7
+
8
+ ## Motivation
9
+ Sorting Ukrainian text correctly is a challenge with Ruby's default sorting mechanism. By default, Ruby sorts strings based on Unicode code points, which does not align with the Ukrainian alphabet.
10
+
11
+ This gem ensures proper sorting according to the Ukrainian alphabet, addressing discrepancies like the placement of 'ґ' and 'є'.
12
+
13
+ ### Приклад / Example
14
+ - Стандартне сортування Ruby / Default sort in Ruby:
15
+ ```
16
+ ["г", "е", "и", "й", "є", "і", "ї", "ґ"]
17
+ ```
18
+ - ukrainian_sort gem:
19
+ ```
20
+ ["г", "ґ", "е", "є", "и", "і", "ї", "й"]
21
+ ```
22
+
23
+ ### Unicode значення / Unicode values
24
+ - г -> 1075
25
+ - ґ -> 1169
26
+ - е -> 1077
27
+ - є -> 1108
28
+ - и -> 1080
29
+ - і -> 1110
30
+ - й -> 1081
31
+ - ї -> 1111
32
+
33
+ ### Сортування за Unicode-кодами (стандартне для Ruby) / Sort by Unicode (default in Ruby)
34
+ ```
35
+ ["г", "е", "и", "й", "є", "і", "ї", "ґ"]
36
+ ```
37
+ ### ukrainian_sort gem:
38
+ ```
39
+ ["г", "ґ", "е", "є", "и", "і", "ї", "й"]
40
+ ```
41
+
42
+
43
+ ## Installation
44
+ Add this line to your application's Gemfile:
45
+
46
+ ```ruby
47
+ gem 'ukrainian_sort'
48
+ ```
49
+
50
+ And then execute:
51
+
52
+ ```bash
53
+ $ bundle install
54
+ ```
55
+
56
+ Or install it yourself as:
57
+
58
+ ```bash
59
+ $ gem install ukrainian_sort
60
+ ```
61
+
62
+ ## Usage
63
+ To sort an array of Ukrainian strings:
64
+
65
+ ```ruby
66
+ require 'ukrainian_sort'
67
+
68
+ words = ["яблуко", "ґава", "виноград", "єдинорог"]
69
+ sorted_words = UkrainianSort.sort(words)
70
+ puts sorted_words
71
+ ```
72
+
73
+ ## Testing
74
+ Run the test suite to ensure everything is working correctly:
75
+
76
+ ```bash
77
+ $ rspec
78
+ ```
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ukrainian_sort'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require 'irb'
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UkrainianSort
4
+ class Sorter
5
+ # Ukrainian alphabet in correct order - each letter position with lowercase first
6
+ UKRAINIAN_ALPHABET = %w[
7
+ а б в г ґ д е є ж з и і
8
+ ї й к л м н о п р с т у
9
+ ф х ц ч ш щ ь ю я
10
+ ].freeze
11
+
12
+ # Create a mapping from each lowercase Ukrainian character to its position
13
+ CHAR_ORDER = UKRAINIAN_ALPHABET.each_with_index.to_h.freeze
14
+
15
+ def initialize
16
+ @char_order = CHAR_ORDER
17
+ end
18
+
19
+ # Sort an array of strings using Ukrainian alphabet order
20
+ def sort(array)
21
+ array.sort { |a, b| compare(a, b) }
22
+ end
23
+
24
+ # Sort an array of strings in descending order
25
+ def sort_desc(array)
26
+ array.sort { |a, b| compare(b, a) }
27
+ end
28
+
29
+ # Compare two strings according to Ukrainian alphabet order
30
+ def compare(str1, str2)
31
+ return 0 if str1 == str2
32
+
33
+ chars1 = normalize(str1)
34
+ chars2 = normalize(str2)
35
+
36
+ [chars1.length, chars2.length].min.times do |i|
37
+ order1 = char_order_position(chars1[i])
38
+ order2 = char_order_position(chars2[i])
39
+ return order1 <=> order2 if order1 != order2
40
+ end
41
+
42
+ # If all compared characters equal, shorter wins
43
+ chars1.length <=> chars2.length
44
+ end
45
+
46
+ private
47
+
48
+ def normalize(str)
49
+ str.downcase.chars.grep(/\p{L}/) # keep all letters
50
+ end
51
+
52
+ def char_order_position(char)
53
+ if @char_order.key?(char)
54
+ @char_order[char]
55
+ else
56
+ 1000 + char.ord # sort non-Ukrainian letters after Ukrainian ones
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UkrainianSort
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UkrainianSort
4
+ class Error < StandardError; end
5
+ end
6
+
7
+ require_relative 'ukrainian_sort/version'
8
+ require_relative 'ukrainian_sort/sorter'
9
+
10
+ module UkrainianSort
11
+ # Convenience method for sorting arrays of strings
12
+ def self.sort(array)
13
+ Sorter.new.sort(array)
14
+ end
15
+
16
+ # Convenience method for sorting arrays of strings in descending order
17
+ def self.sort_desc(array)
18
+ Sorter.new.sort_desc(array)
19
+ end
20
+
21
+ # Convenience method for comparing two strings
22
+ def self.compare(str1, str2)
23
+ Sorter.new.compare(str1, str2)
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ukrainian_sort/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ukrainian_sort'
7
+ spec.version = UkrainianSort::VERSION
8
+ spec.authors = ['mykbren']
9
+ spec.email = ['myk.bren@gmail.com']
10
+
11
+ spec.summary = 'Provides sorting functionality for Ukrainian language strings.'
12
+ spec.description = <<~DESC.strip
13
+ A Ruby gem that implements sorting algorithms specifically designed for Ukrainian language strings,
14
+ ensuring proper handling of unique characters and collation rules.
15
+ DESC
16
+ spec.homepage = 'https://github.com/mykbren/ukrainian_sort'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 3.1.0'
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
+
24
+ # Includes all files tracked by git
25
+ spec.files = Dir.glob('lib/**/*') + Dir.glob('bin/*') + ['README.md', 'CHANGELOG.md', 'LICENSE.txt',
26
+ 'ukrainian_sort.gemspec']
27
+
28
+ spec.bindir = 'bin'
29
+ spec.executables = ['console', 'setup']
30
+ spec.require_paths = ['lib']
31
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ukrainian_sort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mykbren
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ A Ruby gem that implements sorting algorithms specifically designed for Ukrainian language strings,
15
+ ensuring proper handling of unique characters and collation rules.
16
+ email:
17
+ - myk.bren@gmail.com
18
+ executables:
19
+ - console
20
+ - setup
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - CHANGELOG.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/ukrainian_sort.rb
30
+ - lib/ukrainian_sort/sorter.rb
31
+ - lib/ukrainian_sort/version.rb
32
+ - ukrainian_sort.gemspec
33
+ homepage: https://github.com/mykbren/ukrainian_sort
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/mykbren/ukrainian_sort
38
+ source_code_uri: https://github.com/mykbren/ukrainian_sort
39
+ changelog_uri: https://github.com/mykbren/ukrainian_sort/blob/main/CHANGELOG.md
40
+ allowed_push_host: https://rubygems.org
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.1.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.5.14
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Provides sorting functionality for Ukrainian language strings.
60
+ test_files: []