cyrillic 0.2.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84b7f65d75b1416034469c7fbd59f3fd28cd48e9c5808273cec879bef04f0145
4
- data.tar.gz: a0cc60903905063f13f7d4ae390ad22cd3cce194911eb05808a0f67d112eaead
3
+ metadata.gz: 6ccb18a2a8380ecae221098c62b00e1d21654f99020a78a48d921763075adaac
4
+ data.tar.gz: d5ef041b472f740ab9461b67efbeb683b85120adf5a34d5d21d5fa10067a7d30
5
5
  SHA512:
6
- metadata.gz: 4c4fc3f26c1d6d8cf58eddd82ca7e84767277e53fa06db85f757c1fa994abf35216bb19c0776807708380abf0db038ee213d2d88d6f9a146c61d3976f74e486a
7
- data.tar.gz: 98581c63c2d61c5775a690ee1c278aeb180445f9f94d328efc3445ff398ff223678fcbd9de1cea9a63d51a824c4bd64b028d04da6b2997a9ac3400ec9f8e6f6b
6
+ metadata.gz: 8e60b7cb7871b6b7bc0d787cf4520ef0a28dbd2ac63ddb117f1a2d44527191576037f6cf7d269b1e66a157489c56a89c32d5269cf0cd074fec68553427759e3f
7
+ data.tar.gz: 26d33008bf7af9bc70926dff63ce77d0d4cff9542cfd73dc3bd787aae2a0171a35617339684fcbb14401b94e1368f750968f9bbded55d95e9b66f72872de9b4a
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ Exclude:
5
+ - 'bin/**/*'
6
+ - 'pkg/**/*'
7
+ - 'vendor/**/*'
8
+ - 'coverage/**/*'
9
+
10
+ Layout/LineLength:
11
+ AllowedPatterns:
12
+ - '^\s*assert_equal'
13
+ - '^\s*#'
14
+ - '^\s*"'
15
+ - 'spec\.description'
16
+ - 'k = %w\['
17
+ - 'v = %w\['
18
+
19
+ Style/StringLiterals:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/AsciiComments:
26
+ Enabled: false
27
+
28
+ Gemspec/DevelopmentDependencies:
29
+ Enabled: false
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
33
+
34
+ Metrics/MethodLength:
35
+ Enabled: false
36
+
37
+ Metrics/CyclomaticComplexity:
38
+ Enabled: false
39
+
40
+ Metrics/PerceivedComplexity:
41
+ Enabled: false
42
+
43
+ Metrics/BlockLength:
44
+ Enabled: false
45
+
46
+ Metrics/ModuleLength:
47
+ Enabled: false
48
+
49
+ Metrics/CollectionLiteralLength:
50
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,73 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.0] - 2026-09-17
11
+
12
+ ### Added
13
+ - 5 new transliteration schemes:
14
+ - Serbian (`:serbian`) translating Vuk's Cyrillic to Gaj's Latin (`Lj`, `Nj`, `Dž`, `Đ`, `Ć`).
15
+ - GOST 7.79-2000 System B (`:gost779b`) with standard ASCII digraphs.
16
+ - BGN/PCGN 1947 geographic romanization (`:bgn_pcgn`).
17
+ - Bulgarian official Streamlined System (`:bulgarian`).
18
+ - Belarusian national / UN 2012 Łacinka (`:belarusian`).
19
+ - Reverse transliteration (detransliteration) via `Cyrillic.detransliterate` (and aliases `.det`, `.reverse_transliterate`) with reverse mapping tables and longest-token-first greedy matching.
20
+ - CLI flag `-r, --reverse` for reversing transliterated text back to Cyrillic.
21
+ - Comprehensive fixture datasets in `test/fixtures/` and automated test suite in `test/fixtures_test.rb` verifying Ukrainian, Serbian, Bulgarian, Belarusian, Mongolian, and standard international schemes.
22
+ - Comprehensive performance benchmark suite in `benchmark/run.rb` with `rake benchmark` task testing all schemes, detransliteration, and text scale using `benchmark-ips`.
23
+ - Automated YARD documentation generation and deployment to GitHub Pages via `.github/workflows/docs.yml` and `rake yard` task.
24
+ - Documentation link badge in `README.md` and `documentation_uri` gem metadata.
25
+ - CLI executable support and unit test coverage for all new schemes and detransliteration.
26
+
27
+ ## [0.3.0] - 2026-09-17
28
+
29
+ ### Added
30
+ - CLI executable `exe/cyrillic` supporting direct arguments, files, piped STDIN, and scheme flag (`-s`).
31
+ - Integration tests for CLI arguments, flags, files, and STDIN input.
32
+ - GitHub Actions CI workflow for modern Ruby versions (`3.3`, `3.4`, `head`) on `main` branch.
33
+ - Automated GitHub Actions release workflow for building and publishing gem on git tag push.
34
+ - Dependabot configuration for automated Bundler and GitHub Actions dependency updates.
35
+ - Precompiled and cached regular expressions for character tables for improved performance.
36
+ - Case-insensitive scheme resolution (e.g. `:iso9`, `"ISO9"`, `:de`, `"UA_PASSPORT"`).
37
+ - Informative `ArgumentError` when an unknown transliteration scheme is specified.
38
+ - Standard gem metadata URIs (`source_code_uri`, `changelog_uri`, `bug_tracker_uri`, `rubygems_mfa_required`).
39
+ - Comprehensive YARD documentation with examples for `Cyrillic.transliterate` and `Cyrillic.t`.
40
+ - SimpleCov test coverage tracking achieving 100% line coverage.
41
+ - Unit tests for edge cases (nil, empty strings, scheme normalization, error handling).
42
+
43
+ ### Changed
44
+ - Namespaced scheme modules under `Cyrillic` (`Cyrillic::Iso9`, `Cyrillic::Mongolian`, `Cyrillic::Ukrainian`, `Cyrillic::UaPassport`, `Cyrillic::De`) with backwards-compatible top-level aliases.
45
+ - Set minimum required Ruby version to `>= 3.3.0` in gemspec.
46
+ - Update development dependencies (rubocop, rake, rdoc, irb, minitest, simplecov).
47
+ - Untrack `Gemfile.lock` and add to `.gitignore` following gem development best practices.
48
+ - Add `.gitattributes` for consistent LF line endings and diff drivers.
49
+ - Integrate RuboCop code style checks into default `rake` task.
50
+ - Update copyright year to 2018-2026 in `LICENSE.txt`.
51
+
52
+ ### Fixed
53
+ - Eliminate mutable string literal warnings under Ruby 3.4+ in Ukrainian Passport transliteration.
54
+ - Fix character mappings and duplicate key warnings in ISO 9 table (`ӵ` and `ҿ`).
55
+
56
+ ### Removed
57
+ - Legacy `.travis.yml` configuration.
58
+ - Empty 0-byte placeholder files from `lib/cyrillic/`.
59
+
60
+ ## [0.2.0] - 2025-11-09
61
+
62
+ ### Added
63
+ - ISO 9 transliteration support (`:iso9`).
64
+ - Mongolian transliteration support (`:mongolian`).
65
+ - Ukrainian transliteration support (`:ukrainian`).
66
+ - Ukrainian passport transliteration standard support (`:ua_passport`).
67
+ - German transliteration standard support (`:de`).
68
+
69
+ ## [0.1.0] - 2018-04-05
70
+
71
+ ### Added
72
+ - Initial release.
73
+ - Core Cyrillic transliteration to Roman (Latin) script.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 rovetz
3
+ Copyright (c) 2018-2026 rovetz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,26 +1,32 @@
1
- # Cyrillic -> Latin: Cyrillic.t("Кириллица") => "Kirillitsa"
1
+ # Cyrillic
2
2
 
3
+ [![Ruby](https://github.com/rovetz/cyrillic/actions/workflows/ruby.yml/badge.svg)](https://github.com/rovetz/cyrillic/actions/workflows/ruby.yml)
4
+ [![Docs](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://rovetz.github.io/cyrillic/)
3
5
  [![Gem Version](https://badge.fury.io/rb/cyrillic.svg)](https://badge.fury.io/rb/cyrillic)
4
- [![Build Status](https://travis-ci.org/rovetz/cyrillic.svg?branch=main)](https://travis-ci.org/rovetz/cyrillic)
5
6
  [![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
- **Cyrillic** is a Ruby gem for the romanization (transliteration) of Cyrillic script into the Latin alphabet. It provides a simple and flexible way to convert Cyrillic text using various international and language-specific standards.
8
+ **Cyrillic** is a Ruby gem for romanization (transliteration) of Cyrillic script into the Roman (Latin) alphabet. It provides a simple and flexible interface with support for international and national standards.
8
9
 
9
- ## Features
10
+ ## Supported Schemes
10
11
 
11
- This gem supports multiple transliteration standards:
12
-
13
- * `generic` (Default)
14
- * `iso9`
15
- * `ukrainian`
16
- * `mongolian`
12
+ * `:cyrillic` (Default generic Cyrillic transliteration)
13
+ * `:iso9` (ISO 9:1995 international standard)
14
+ * `:serbian` (Serbian Vuk's Cyrillic to Gaj's Latin)
15
+ * `:gost779b` (GOST 7.79-2000 System B ASCII digraphs)
16
+ * `:bgn_pcgn` (BGN/PCGN 1947 geographic romanization)
17
+ * `:bulgarian` (Bulgarian official Streamlined System)
18
+ * `:belarusian` (Belarusian national / UN 2012 Łacinka)
19
+ * `:ukrainian` (Ukrainian national standard)
20
+ * `:ua_passport` (Ukrainian international passport standard)
21
+ * `:mongolian` (Mongolian Cyrillic MNS 5217:2012)
22
+ * `:de` (German Duden/phonetic transliteration)
17
23
 
18
24
  ## Installation
19
25
 
20
26
  Add this line to your application's Gemfile:
21
27
 
22
28
  ```ruby
23
- gem 'cyrillic'
29
+ gem "cyrillic"
24
30
  ```
25
31
 
26
32
  And then execute:
@@ -33,53 +39,123 @@ Or install it yourself as:
33
39
 
34
40
  ## Usage
35
41
 
36
- The gem provides a simple interface through the `Cyrillic.t` (or `Cyrillic.transliterate`) method.
37
-
38
- ### Basic Usage
39
-
40
- By default, it uses a generic transliteration scheme.
41
-
42
42
  ```ruby
43
43
  require "cyrillic"
44
44
 
45
+ # Default Cyrillic transliteration
46
+ Cyrillic.transliterate("Кириллица")
47
+ # => "KirilliTSa"
48
+
49
+ # Short alias .t
45
50
  Cyrillic.t("Кириллица")
46
- #=> "Kirillitsa"
47
- ```
51
+ # => "KirilliTSa"
48
52
 
49
- ### Specifying a Standard
53
+ # ISO 9:1995 scheme
54
+ Cyrillic.t("Не важно, как медленно ты продвигаешься", :iso9)
55
+ # => "Ne važno, kak medlenno ty prodvigaešʹsâ"
50
56
 
51
- You can specify a transliteration standard by passing a symbol as the second argument.
57
+ # Serbian Cyrillic to Latin (Vukovica to Gajica)
58
+ Cyrillic.t("Љубљана", :serbian)
59
+ # => "Ljubljana"
52
60
 
53
- #### ISO 9
61
+ # GOST 7.79-2000 System B (ASCII digraphs)
62
+ Cyrillic.t("Щука", :gost779b)
63
+ # => "Shhuka"
54
64
 
55
- ```ruby
56
- Cyrillic.transliterate("Кириллица", :iso9)
57
- #=> "Kirillica"
58
- ```
65
+ # BGN/PCGN 1947 geographic romanization
66
+ Cyrillic.t("Хабаровск", :bgn_pcgn)
67
+ # => "Khabarovsk"
59
68
 
60
- #### Ukrainian
69
+ # Bulgarian Streamlined System
70
+ Cyrillic.t("България", :bulgarian)
71
+ # => "Balgariya"
61
72
 
62
- ```ruby
63
- Cyrillic.transliterate("Кирилиця", :ukrainian)
64
- #=> "Kyrylytsia"
65
- ```
73
+ # Belarusian national / UN 2012 Łacinka
74
+ Cyrillic.t("Мінск", :belarusian)
75
+ # => "Minsk"
66
76
 
67
- #### Mongolian
77
+ # Ukrainian scheme
78
+ Cyrillic.t("Київ", :ukrainian)
79
+ # => "Kyiv"
68
80
 
69
- ```ruby
81
+ # Ukrainian passport scheme
82
+ Cyrillic.t("Борщагівка", :ua_passport)
83
+ # => "Borshchahivka"
84
+
85
+ # Mongolian scheme
70
86
  Cyrillic.t("Монгол хэл", :mongolian)
71
- #=> "Mongol khel"
87
+ # => "Mongol khel"
88
+
89
+ # German transliteration scheme
90
+ Cyrillic.t("Чайковский", :de)
91
+ # => "Tschajkowskij"
92
+
93
+ # Reverse transliteration (Detransliteration)
94
+ Cyrillic.detransliterate("Transliteraciâ", :iso9)
95
+ # => "Транслитерация"
96
+
97
+ # Short alias .det
98
+ Cyrillic.det("Ljubljana", :serbian)
99
+ # => "Љубљана"
72
100
  ```
73
101
 
74
- ## Development
102
+ ### Command Line Interface (CLI)
75
103
 
76
- After checking out the repo, run `bin/setup` to install development dependencies.
104
+ You can also use `cyrillic` directly from your terminal:
77
105
 
78
- To run the test suite, use the `rake` command:
106
+ ```bash
107
+ # Direct argument
108
+ $ cyrillic "Кириллица"
109
+ KirilliTSa
110
+
111
+ # Piped input (STDIN)
112
+ $ echo "Кириллица" | cyrillic
113
+ KirilliTSa
114
+
115
+ # File input
116
+ $ cyrillic text.txt
117
+
118
+ # Specify transliteration scheme
119
+ $ cyrillic -s iso9 "Транслитерация"
120
+ Transliteraciâ
121
+
122
+ $ cyrillic -s serbian "Љубљана"
123
+ Ljubljana
124
+
125
+ $ cyrillic -s gost779b "Щука"
126
+ Shhuka
127
+
128
+ $ cyrillic -s bgn_pcgn "Хабаровск"
129
+ Khabarovsk
130
+
131
+ $ cyrillic -s bulgarian "България"
132
+ Balgariya
133
+
134
+ $ cyrillic -s belarusian "Мінск"
135
+ Minsk
136
+
137
+ $ cyrillic -s ukrainian "Київ"
138
+ Kyiv
139
+
140
+ $ cyrillic -s ua_passport "Борщагівка"
141
+ Borshchahivka
142
+
143
+ $ cyrillic -s de "Весна"
144
+ Wesna
145
+
146
+ # Reverse transliteration (-r, --reverse)
147
+ $ cyrillic -r "Transliteraciâ"
148
+ Транслитерация
149
+
150
+ $ cyrillic -r -s serbian "Ljubljana"
151
+ Љубљана
152
+ ```
153
+
154
+ ## Development
79
155
 
80
- $ rake
156
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run tests and code style checks (RuboCop). You can run performance benchmarks with `bundle exec rake benchmark`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
157
 
82
- You can also run `bin/console` for an interactive prompt that will allow you to experiment with the gem.
158
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
159
 
84
160
  ## Contributing
85
161
 
@@ -91,4 +167,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
91
167
 
92
168
  ## Code of Conduct
93
169
 
94
- Everyone interacting in the Cyrillic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/cyrillic/blob/master/CODE_OF_CONDUCT.md).
170
+ Everyone interacting in the Cyrillic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/cyrillic/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
@@ -7,4 +10,20 @@ Rake::TestTask.new(:test) do |t|
7
10
  t.test_files = FileList["test/**/*_test.rb"]
8
11
  end
9
12
 
10
- task :default => :test
13
+ RuboCop::RakeTask.new(:rubocop)
14
+
15
+ desc "Run performance benchmarks"
16
+ task :benchmark do
17
+ ruby "benchmark/run.rb"
18
+ end
19
+
20
+ begin
21
+ require "yard"
22
+ YARD::Rake::YardocTask.new do |t|
23
+ t.files = ["lib/**/*.rb", "-", "README.md", "CHANGELOG.md", "LICENSE.txt"]
24
+ end
25
+ rescue LoadError
26
+ # YARD not available
27
+ end
28
+
29
+ task default: %i[test rubocop]
data/benchmark/run.rb ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "benchmark/ips"
4
+ require_relative "../lib/cyrillic"
5
+
6
+ SHORT_TEXT = "Не важно, как медленно ты продвигаешься, главное, что ты не останавливаешься."
7
+ PARAGRAPH_TEXT = [
8
+ "Весна пришла в город с первыми теплыми лучами солнца и ароматом цветущих садов.",
9
+ "На центральных улицах кипела жизнь: открывались уютные кафе, люди гуляли по набережной.",
10
+ "Каждый новый день приносил вдохновение, надежду и стремление к созиданию прекрасного будущего.",
11
+ "В библиотеках и университетах студенты усердно готовились к весенним экзаменам и научным конференциям."
12
+ ].join(" ")
13
+ LONG_TEXT = "#{PARAGRAPH_TEXT} " * 30
14
+
15
+ puts "=" * 60
16
+ puts "Cyrillic Gem Performance Benchmarks"
17
+ puts "Ruby: #{RUBY_DESCRIPTION}"
18
+ puts "=" * 60
19
+
20
+ puts "\n[1] Schemes Comparison (Paragraph Text, ~350 chars)"
21
+ Benchmark.ips do |x|
22
+ x.config(time: 1, warmup: 0.5)
23
+
24
+ %i[cyrillic iso9 serbian gost779b bgn_pcgn bulgarian belarusian mongolian ukrainian ua_passport de].each do |scheme|
25
+ x.report(scheme.to_s) do
26
+ Cyrillic.t(PARAGRAPH_TEXT, scheme)
27
+ end
28
+ end
29
+
30
+ x.compare!
31
+ end
32
+
33
+ puts "\n[2] Forward vs Reverse Transliteration (ISO 9 & Serbian)"
34
+ iso9_latin = Cyrillic.t(PARAGRAPH_TEXT, :iso9)
35
+ serbian_cyr = "Београд, Нови Сад, Ниш, Крагујевац, Суботица, Зрењанин, Панчево, Чачак, Краљево, Ваљево."
36
+ serbian_lat = Cyrillic.t(serbian_cyr, :serbian)
37
+
38
+ Benchmark.ips do |x|
39
+ x.config(time: 1, warmup: 0.5)
40
+
41
+ x.report("iso9 forward") { Cyrillic.t(PARAGRAPH_TEXT, :iso9) }
42
+ x.report("iso9 reverse") { Cyrillic.det(iso9_latin, :iso9) }
43
+ x.report("serbian fwd") { Cyrillic.t(serbian_cyr, :serbian) }
44
+ x.report("serbian rev") { Cyrillic.det(serbian_lat, :serbian) }
45
+
46
+ x.compare!
47
+ end
48
+
49
+ puts "\n[3] Scalability by Text Size (ISO 9: short, medium, long)"
50
+ Benchmark.ips do |x|
51
+ x.config(time: 1, warmup: 0.5)
52
+
53
+ x.report("short (~75 chars)") { Cyrillic.t(SHORT_TEXT, :iso9) }
54
+ x.report("medium (~350 chars)") { Cyrillic.t(PARAGRAPH_TEXT, :iso9) }
55
+ x.report("long (~10,500 chars)") { Cyrillic.t(LONG_TEXT, :iso9) }
56
+
57
+ x.compare!
58
+ end
data/cyrillic.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
4
6
  require "cyrillic/version"
5
7
 
6
8
  Gem::Specification.new do |spec|
@@ -10,17 +12,34 @@ Gem::Specification.new do |spec|
10
12
  spec.email = ["zakbox@gmail.com"]
11
13
 
12
14
  spec.summary = "Romanization (transliteration) of Cyrillic"
13
- spec.description = "Romanization (transliteration) of Cyrillic. Converts Cyrillic text to the Roman (Latin) script"
15
+ spec.description = "Converts Cyrillic text to the Roman (Latin) script"
14
16
  spec.homepage = "https://github.com/rovetz/cyrillic"
15
17
  spec.license = "MIT"
18
+ spec.required_ruby_version = ">= 3.3.0"
19
+
20
+ spec.metadata["source_code_uri"] = "https://github.com/rovetz/cyrillic"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rovetz/cyrillic/blob/main/CHANGELOG.md"
22
+ spec.metadata["bug_tracker_uri"] = "https://github.com/rovetz/cyrillic/issues"
23
+ spec.metadata["documentation_uri"] = "https://rovetz.github.io/cyrillic/"
24
+ spec.metadata["rubygems_mfa_required"] = "true"
16
25
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").select { |f| File.file?(f) }.reject do |f|
28
+ (File.expand_path(f) == __FILE__) ||
29
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github Gemfile])
30
+ end
19
31
  end
20
32
  spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.executables = ["cyrillic"]
22
34
  spec.require_paths = ["lib"]
23
35
 
24
- spec.add_development_dependency "rake", "~> 13.0"
25
- spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "benchmark"
37
+ spec.add_development_dependency "benchmark-ips"
38
+ spec.add_development_dependency "irb"
39
+ spec.add_development_dependency "minitest", ">= 5.25"
40
+ spec.add_development_dependency "rake", ">= 13.2"
41
+ spec.add_development_dependency "rdoc"
42
+ spec.add_development_dependency "rubocop", ">= 1.64"
43
+ spec.add_development_dependency "simplecov", ">= 0.22"
44
+ spec.add_development_dependency "yard", ">= 0.9.36"
26
45
  end
data/exe/cyrillic ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "optparse"
5
+ require "cyrillic"
6
+
7
+ scheme = nil
8
+ reverse = false
9
+
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = "Usage: cyrillic [options] [text | file...]"
12
+ opts.separator ""
13
+ opts.separator "Transliterate Cyrillic script to Roman (Latin) script, or reverse with -r."
14
+ opts.separator ""
15
+ opts.separator "Examples:"
16
+ opts.separator " cyrillic 'Кириллица'"
17
+ opts.separator " echo 'Кириллица' | cyrillic"
18
+ opts.separator " cyrillic -r 'Transliteraciâ'"
19
+ opts.separator " cyrillic -s serbian 'Љубљана'"
20
+ opts.separator " cyrillic -r -s serbian 'Ljubljana'"
21
+ opts.separator " cyrillic -r -s gost779b 'Shhuka'"
22
+ opts.separator ""
23
+ opts.separator "Options:"
24
+
25
+ schemes = %w[default cyrillic iso9 mongolian ukrainian ua_passport de serbian gost779b bgn_pcgn bulgarian belarusian]
26
+ opts.on("-s", "--scheme SCHEME", schemes,
27
+ "Transliteration scheme (#{schemes.join(', ')})") do |s|
28
+ scheme = s == "default" ? nil : s.to_sym
29
+ end
30
+
31
+ opts.on("-r", "--reverse", "Reverse transliteration (Latin to Cyrillic)") do
32
+ reverse = true
33
+ end
34
+
35
+ opts.on("-v", "--version", "Show version") do
36
+ puts "cyrillic #{Cyrillic::VERSION}"
37
+ exit
38
+ end
39
+
40
+ opts.on("-h", "--help", "Show this help message") do
41
+ puts opts
42
+ exit
43
+ end
44
+ end
45
+
46
+ parser.parse!
47
+
48
+ process = lambda do |text|
49
+ if reverse
50
+ Cyrillic.detransliterate(text, from: scheme || :iso9)
51
+ else
52
+ Cyrillic.transliterate(text, scheme || :cyrillic)
53
+ end
54
+ end
55
+
56
+ if ARGV.empty?
57
+ if $stdin.tty?
58
+ puts parser
59
+ exit 1
60
+ else
61
+ $stdin.each_line do |line|
62
+ puts process.call(line.chomp)
63
+ end
64
+ end
65
+ else
66
+ ARGV.each do |arg|
67
+ if File.file?(arg)
68
+ File.foreach(arg) do |line|
69
+ puts process.call(line.chomp)
70
+ end
71
+ else
72
+ puts process.call(arg)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cyrillic
4
+ # Belarusian national / UN 2012 Łacinka transliteration.
5
+ module Belarusian
6
+ k = %w[
7
+ А Б В Г Д Е Ё Ж З І Й К Л М Н О П Р С Т У Ў Ф Х Ц Ч Ш Ы Ь Э Ю Я
8
+ а б в г д е ё ж з і й к л м н о п р с т у ў ф х ц ч ш ы ь э ю я
9
+ ].freeze
10
+
11
+ v = %w[
12
+ A B V H D E Jo Ž Z I J K L M N O P R S T U Ŭ F Ch C Č Š Y ' E Ju Ja
13
+ a b v h d e jo ž z i j k l m n o p r s t u ŭ f ch c č š y ' e ju ja
14
+ ].freeze
15
+
16
+ CHARACTER_TABLE = k.zip(v).to_h.freeze
17
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
18
+ end
19
+ end
20
+
21
+ Belarusian = Cyrillic::Belarusian unless defined?(Belarusian)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cyrillic
4
+ # BGN/PCGN 1947 geographic romanization system.
5
+ module BgnPcgn
6
+ k = %w[
7
+ А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я
8
+ а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я
9
+ ].freeze
10
+
11
+ v = %w[
12
+ A B V G D E Yo Zh Z I Y K L M N O P R S T U F Kh Ts Ch Sh Shch " Y ' E Yu Ya
13
+ a b v g d e yo zh z i y k l m n o p r s t u f kh ts ch sh shch " y ' e yu ya
14
+ ].freeze
15
+
16
+ CHARACTER_TABLE = k.zip(v).to_h.freeze
17
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
18
+ end
19
+ end
20
+
21
+ BgnPcgn = Cyrillic::BgnPcgn unless defined?(BgnPcgn)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cyrillic
4
+ # Bulgarian official Streamlined System (2006/2009) transliteration.
5
+ module Bulgarian
6
+ k = %w[
7
+ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ь Ю Я
8
+ а б в г д е ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ь ю я
9
+ ].freeze
10
+
11
+ v = %w[
12
+ A B V G D E Zh Z I Y K L M N O P R S T U F H Ts Ch Sh Sht A Y Yu Ya
13
+ a b v g d e zh z i y k l m n o p r s t u f h ts ch sh sht a y yu ya
14
+ ].freeze
15
+
16
+ CHARACTER_TABLE = k.zip(v).to_h.freeze
17
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
18
+ end
19
+ end
20
+
21
+ Bulgarian = Cyrillic::Bulgarian unless defined?(Bulgarian)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cyrillic
4
+ # German (Duden/phonetic) transliteration system.
5
+ module De
6
+ k = %w[А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я].freeze
7
+ v = %w[A B W G D E Jo Sch S I J K L M N O P R S T U F Ch Z Tsch Sch Schtsch "" Y "" E Ju Ja a b w g d e jo sch s i j k l m n o p r s t u f ch z tsch sch schtsch "" y "" e ju ja].freeze
8
+
9
+ CHARACTER_TABLE = k.zip(v).to_h.freeze
10
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
11
+ end
12
+ end
13
+
14
+ De = Cyrillic::De unless defined?(De)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cyrillic
4
+ # GOST 7.79-2000 System B (ISO 9 System B) ASCII digraphs transliteration.
5
+ module Gost779b
6
+ k = %w[
7
+ А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я
8
+ а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я
9
+ ].freeze
10
+
11
+ v = %w[
12
+ A B V G D E Yo Zh Z I J K L M N O P R S T U F X Cz Ch Sh Shh " Y ' E' Yu Ya
13
+ a b v g d e yo zh z i j k l m n o p r s t u f x cz ch sh shh " y ' e' yu ya
14
+ ].freeze
15
+
16
+ CHARACTER_TABLE = k.zip(v).to_h.freeze
17
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
18
+ end
19
+ end
20
+
21
+ Gost779b = Cyrillic::Gost779b unless defined?(Gost779b)