├── .github └── workflows │ └── spec.yml ├── .gitignore ├── .gitmodules ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── iiulia.gemspec ├── lib ├── iuliia.rb └── iuliia │ ├── exceptions.rb │ ├── iuliia.rb │ ├── schema.rb │ ├── translit.rb │ └── version.rb ├── priv └── evrone-sponsored-logo.png └── spec ├── iuliia ├── iuliia_spec.rb ├── schema_spec.rb └── translit_spec.rb └── spec_helper.rb /.github/workflows/spec.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake 6 | # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby 7 | 8 | name: Ruby 9 | 10 | on: 11 | push: 12 | branches: 13 | - master 14 | - release-* 15 | pull_request: 16 | branches: [ master ] 17 | 18 | jobs: 19 | test: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v2 23 | with: 24 | submodules: 'true' 25 | - name: Set up Ruby 26 | uses: ruby/setup-ruby@v1 27 | with: 28 | ruby-version: 2.6 29 | - name: Install dependencies 30 | run: bundle install 31 | - name: Run tests 32 | run: bundle exec rspec 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | 10 | # rspec failure tracking 11 | .rspec_status 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/schemas"] 2 | path = lib/schemas 3 | url = https://github.com/nalgeon/iuliia 4 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | 3 | AllCops: 4 | DisplayCopNames: true 5 | NewCops: enable 6 | 7 | Style/Documentation: 8 | Enabled: false 9 | 10 | Metrics/BlockLength: 11 | Max: 30 12 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config --exclude-limit 1000` 3 | # on 2020-09-14 09:10:34 UTC using RuboCop version 0.90.0. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 1 10 | # Configuration parameters: Include. 11 | # Include: **/*.gemspec 12 | Gemspec/RequiredRubyVersion: 13 | Exclude: 14 | - 'iiulia.gemspec' 15 | 16 | # Offense count: 1 17 | # Configuration parameters: MinBodyLength. 18 | Style/GuardClause: 19 | Exclude: 20 | - 'iiulia.gemspec' 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: false 3 | language: ruby 4 | cache: bundler 5 | rvm: 6 | - 2.6.6 7 | before_install: gem install bundler -v 1.17.3 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.0.1] - 2020-09-25 8 | #### Deprecations 9 | Method `translit` now deprecated, use `translate` instead. Will be removed completely in the future releases. 10 | #### Improvements 11 | Now call for translate with wrong (non-existent) schema will throw more human-friendly exception. 12 | 13 | ## [1.0.0] - 2020-09-14 14 | This is the new initial version for gem `iuliia` after renaming it from `iuliia-rb` 15 | 16 | ## [0.2.1] - 2020-09-14 17 | Changes: 18 | * Gem has been renamed to `iuliia`. This is the last version of `iuliia-rb`. Please, use `iuliia` instead. 19 | 20 | ## [0.2.0] - 2020-09-14 21 | Changes: 22 | * Moved `lib/schemas` to the git submodule `github.com/nalgeon/iuliia` 23 | * Lazy loading for schemas 24 | 25 | ## [0.1.0] - 2020-04-30 26 | ### Initial release -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } 6 | 7 | # Specify your gem's dependencies in iiulia.gemspec 8 | gemspec 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Andrey Nikiforov 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Iuliia 2 | 3 | Small gem to properly transliterate cyrillic to latin. Use https://github.com/nalgeon/iuliia for transliteration schemas. 4 | 5 | ![Ruby](https://github.com/adnikiforov/iuliia-rb/workflows/Ruby/badge.svg) 6 | 7 | ## Installation 8 | 9 | #### Gem has been renamed to `iuliia`. This is the last version of `iuliia-rb`. Please, use `iuliia` instead. 10 | 11 | Add this line to your application's Gemfile: 12 | 13 | ```ruby 14 | gem 'iuliia' 15 | ``` 16 | 17 | And then execute: 18 | 19 | $ bundle 20 | 21 | Or install it yourself as: 22 | 23 | $ gem install iuliia 24 | 25 | ## Usage 26 | 27 | Get available schemas (dynamically generated from JSON definitions in `lib/schemas`) 28 | ```ruby 29 | Iuliia::Schema.available_schemas 30 | 31 | [ 32 | ['mvd_310', 'MVD 310-1997 transliteration schema'], 33 | ['bs_2979', 'British Standard 2979:1958 transliteration schema'], 34 | ['gost_779_alt', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'], 35 | ['icao_doc_9303', 'ICAO DOC 9303 transliteration schema'], 36 | ['mvd_310_fr', 'MVD 310-1997 transliteration schema'], 37 | ['mvd_782', 'MVD 782-2000 transliteration schema'], 38 | ['iso_9_1968_alt', 'ISO/R 9:1968 transliteration schema'], 39 | ['mosmetro', 'Moscow Metro map transliteration schema'], 40 | ['gost_7034', 'GOST R 7.0.34-2014 transliteration schema'], 41 | ['gost_16876_alt', 'GOST 16876-71 (aka GOST 1983) transliteration schema'], 42 | ['gost_52290', 'GOST R 52290-2004 transliteration schema'], 43 | ['ungegn_1987', 'UNGEGN 1987 V/18 transliteration schema'], 44 | ['telegram', 'Telegram transliteration schema'], 45 | ['gost_16876', 'GOST 16876-71 (aka GOST 1983) transliteration schema'], 46 | ['gost_779', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'], 47 | ['wikipedia', 'Wikipedia transliteration schema'], 48 | ['bgn_pcgn', 'BGN/PCGN transliteration schema'], 49 | ['iso_9_1968', 'ISO/R 9:1968 transliteration schema'], 50 | ['yandex_money', 'Yandex.Money transliteration schema'], 51 | ['ala_lc', 'ALA-LC transliteration schema.'], 52 | ['yandex_maps', 'Yandex.Maps transliteration schema'], 53 | ['gost_52535', 'GOST R 52535.1-2006 transliteration schema'], 54 | ['bgn_pcgn_alt', 'BGN/PCGN transliteration schema'], 55 | ['iso_9_1954', 'ISO/R 9:1954 transliteration schema'], 56 | ['bs_2979_alt', 'British Standard 2979:1958 transliteration schema'], 57 | ['scientific', 'Scientific transliteration schema'], 58 | ['ala_lc_alt', 'ALA-LC transliteration schema.'] 59 | ] 60 | ``` 61 | 62 | Pick one and transliterate 63 | 64 | ```ruby 65 | Iuliia.translate('Юлия, съешь ещё этих мягких французских булок из Йошкар-Олы, да выпей алтайского чаю', schema: 'mvd_782') 66 | 67 | "Yuliya, syesh' eshche etikh myagkikh frantsuzskikh bulok iz Yoshkar-Oly, da vypey altayskogo chayu" 68 | ``` 69 | 70 | ## TODO 71 | 72 | * ~~Add documentation~~ 73 | * Maybe some more specs 74 | * Implement reverse translit (not available for all schemas though): https://github.com/adnikiforov/iuliia-rb/issues/3 75 | 76 | ## Development 77 | 78 | Check out repo: 79 | 80 | ``` 81 | git clone git@github.com:adnikiforov/iuliia-rb.git 82 | ``` 83 | 84 | Check out submodule with schemas: 85 | 86 | ``` 87 | git submodule update --init 88 | ``` 89 | 90 | Setup dependencies: 91 | 92 | ``` 93 | bin/setup 94 | ``` 95 | 96 | Run specs: 97 | 98 | ``` 99 | bundle exec rspec 100 | ``` 101 | 102 | Or open console to try it: 103 | 104 | ``` 105 | bin/console 106 | ``` 107 | 108 | To install this gem onto your local machine, run `bundle exec rake install`. 109 | 110 | ## Support 111 | 112 |

113 | 114 | Sponsored by Evrone 116 | 117 |

118 | 119 | ## License 120 | 121 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 122 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | 8 | task default: :spec 9 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'bundler/setup' 5 | require 'iuliia' 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 | # (If you use this, don't forget to add pry to your Gemfile!) 11 | # require "pry" 12 | # Pry.start 13 | 14 | require 'irb' 15 | IRB.start(__FILE__) 16 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /iiulia.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'iuliia/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'iuliia' 9 | spec.version = Iuliia::VERSION 10 | spec.authors = ['Andrey Nikiforov'] 11 | spec.email = ['a.d.nikiforov@gmail.com'] 12 | 13 | spec.summary = 'Russian transliteration using nalgeon/iuliia schemas' 14 | spec.homepage = 'https://github.com/adnikiforov/iuliia-rb' 15 | spec.license = 'MIT' 16 | 17 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 18 | # to allow pushing to a single host or delete this section to allow pushing to any host. 19 | if spec.respond_to?(:metadata) 20 | spec.metadata['homepage_uri'] = spec.homepage 21 | spec.metadata['source_code_uri'] = 'https://github.com/adnikiforov/iuliia-rb' 22 | spec.metadata['changelog_uri'] = 'https://github.com/adnikiforov/iuliia-rb/blob/master/CHANGELOG.md' 23 | else 24 | raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' 25 | end 26 | 27 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 28 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|priv)/}) } 29 | end 30 | 31 | gem_dir = "#{__dir__}/" 32 | `git submodule --quiet foreach pwd`.split($OUTPUT_RECORD_SEPARATOR).each do |submodule_path| 33 | Dir.chdir(submodule_path) do 34 | submodule_relative_path = submodule_path.sub gem_dir, '' 35 | `git ls-files`.split($OUTPUT_RECORD_SEPARATOR).each do |filename| 36 | spec.files << "#{submodule_relative_path}/#{filename}" 37 | end 38 | end 39 | end 40 | 41 | spec.bindir = 'exe' 42 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 43 | spec.require_paths = ['lib'] 44 | 45 | spec.add_development_dependency 'bundler' 46 | spec.add_development_dependency 'rake' 47 | spec.add_development_dependency 'rspec' 48 | spec.add_development_dependency 'rubocop' 49 | spec.add_development_dependency 'rubocop-rake' 50 | spec.add_development_dependency 'rubocop-rspec' 51 | 52 | spec.add_dependency 'json' 53 | end 54 | -------------------------------------------------------------------------------- /lib/iuliia.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'json' 4 | 5 | require 'iuliia/version' 6 | require 'iuliia/translit' 7 | require 'iuliia/schema' 8 | require 'iuliia/iuliia' 9 | require 'iuliia/exceptions' 10 | -------------------------------------------------------------------------------- /lib/iuliia/exceptions.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Iuliia 4 | module Exceptions 5 | class NonExistentSchemaException < StandardError 6 | def initialize(msg = 'Specified schema does not exist') 7 | super 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/iuliia/iuliia.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Iuliia 4 | class << self 5 | # Translate cyrillic string to latin representation 6 | # @param string [String] 7 | # @param schema [Iuliia::Schema] 8 | # @return [String] 9 | def translate(string, schema:) 10 | Iuliia::Translit.new(string, schema).translit 11 | end 12 | 13 | def translit(string, schema:) 14 | warn 'translit is deprecated, use .translate instead' 15 | translate(string, schema: schema) 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/iuliia/schema.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Iuliia 4 | module Schema 5 | class << self 6 | # Fetch schema by schema name 7 | # @param schema_name [String] 8 | # @return [Iuliia::Schema] 9 | def [](schema_name) 10 | schemas[schema_name] 11 | end 12 | 13 | # @deprecated 14 | alias schema [] 15 | 16 | # Return list of available schemas 17 | # @return [Array] 18 | def available_schemas 19 | load_schemas.transform_values(&:description).to_a 20 | end 21 | 22 | private 23 | 24 | def lib_dir 25 | File.expand_path('..', __dir__) 26 | end 27 | 28 | def schemas 29 | @schemas ||= Hash.new { |h, k| h[k] = load_schema(k) } 30 | end 31 | 32 | def load_schema(name) 33 | filename = "#{lib_dir}/schemas/#{name}.json" 34 | raise Exceptions::NonExistentSchemaException unless File.exist?(filename) 35 | 36 | JSON.parse(File.read(filename), object_class: OpenStruct, symbolize_names: true) 37 | end 38 | 39 | def load_schemas 40 | Dir["#{lib_dir}/schemas/*.json"].map do |file| 41 | schema = load_schema(File.basename(file, '.json')) 42 | [schema.name, schema] 43 | end.to_h 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/iuliia/translit.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Iuliia 4 | class Translit 5 | ENDING_LENGTH = 2 6 | private_constant :ENDING_LENGTH 7 | 8 | # Initialize transliterator engine with string and schema 9 | # @param string [String] 10 | # @param schema [Iuliia::Schema] 11 | # @return [Iuliia::Translit] 12 | def initialize(string, schema) 13 | @string = string 14 | @schema = Iuliia::Schema[schema] 15 | end 16 | 17 | # Translit cyrillic string to latin representation 18 | # @return [String] 19 | def translit 20 | return unless schema 21 | 22 | string.split(/\b/).map { |chunk| translit_chunk(chunk) }.join 23 | end 24 | 25 | private 26 | 27 | attr_reader :string, :schema 28 | 29 | def translit_chunk(chunk) 30 | return chunk unless /\p{l}+/.match?(chunk) 31 | 32 | stem, ending = split_word(chunk) 33 | 34 | return translit_stem(chunk) if ending.empty? 35 | 36 | translited_ending = schema.ending_mapping&.dig(ending) 37 | return translit_stem(chunk) if translited_ending.nil? 38 | 39 | translited_stem = translit_stem(stem) 40 | 41 | [translited_stem, translited_ending].join 42 | end 43 | 44 | def translit_stem(stem) 45 | translited_stem = stem.chars.each_with_index.map do |char, index| 46 | translit_char(stem.chars, char, index) 47 | end 48 | 49 | string = translited_stem.join 50 | return camelcase(translited_stem.join) unless upcase?(translited_stem.join) 51 | 52 | string 53 | end 54 | 55 | def translit_char(chars, char, index) 56 | return char unless /[А-Яа-яёЁ]/.match?(char) 57 | 58 | translited_char = translit_prev(chars, index) 59 | translited_char = translit_next(chars, index) if translited_char.nil? 60 | translited_char = schema.mapping[char.downcase] if translited_char.nil? 61 | 62 | upcase?(char) ? camelcase(translited_char.upcase) : translited_char 63 | end 64 | 65 | def translit_prev(chars, index) 66 | prev_char = 67 | if index.positive? 68 | chars[index - 1..index].join.downcase 69 | else 70 | chars[index].downcase 71 | end 72 | 73 | schema.prev_mapping&.dig(prev_char) 74 | end 75 | 76 | def translit_next(chars, index) 77 | next_char = chars[index..index + 1].join.downcase 78 | schema.next_mapping&.dig(next_char) 79 | end 80 | 81 | def split_word(word) 82 | if word.length <= ENDING_LENGTH 83 | [word, ''] 84 | else 85 | ending = word.length > ENDING_LENGTH ? word[-ENDING_LENGTH..-1] : '' 86 | stem = word[0..(word.length - ENDING_LENGTH - 1)] || word 87 | 88 | [stem, ending] 89 | end 90 | end 91 | 92 | def upcase?(char) 93 | /[[:upper:]]/.match(char) 94 | end 95 | 96 | def camelcase(string) 97 | return string unless upcase?(string[0]) 98 | 99 | string = string.downcase 100 | string[0] = string[0].capitalize 101 | string 102 | end 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /lib/iuliia/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Iuliia 4 | VERSION = '1.0.4' 5 | end 6 | -------------------------------------------------------------------------------- /priv/evrone-sponsored-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adnikiforov/iuliia-rb/f79f0e4c59b1265f583b5aef63d5f80dfc3d56b5/priv/evrone-sponsored-logo.png -------------------------------------------------------------------------------- /spec/iuliia/iuliia_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rspec' 4 | 5 | describe Iuliia do 6 | describe '#translit' do 7 | let(:string) { 'whenever' } 8 | let(:schema) { Iuliia::Schema.available_schemas.sample[0] } 9 | 10 | context 'with existing schema' do 11 | before do 12 | expect_any_instance_of(Iuliia::Translit).to receive(:translit) 13 | end 14 | 15 | it 'does call for translit' do 16 | described_class.translit(string, schema: schema) 17 | end 18 | end 19 | 20 | context 'without existing schema' do 21 | let(:schema) { :non_existent_schema } 22 | let(:error) { Iuliia::Exceptions::NonExistentSchemaException } 23 | let(:error_message) { 'Specified schema does not exist' } 24 | 25 | it 'raises Exceptions::NonExistentSchemaException' do 26 | expect { described_class.translit(string, schema: schema) }.to raise_error(error, error_message) 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/iuliia/schema_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rspec' 4 | 5 | describe Iuliia::Schema do 6 | describe '#[]' do 7 | subject { Iuliia::Schema[schema.to_sym] } 8 | 9 | context 'with existing schema' do 10 | let(:schema) { Iuliia::Schema.available_schemas.sample[0].to_sym } 11 | 12 | it 'opens the schema' do 13 | expect(subject.class).to eq(OpenStruct) 14 | end 15 | end 16 | 17 | context 'without existing schema' do 18 | let(:schema) { :non_existent_schema } 19 | let(:error) { Iuliia::Exceptions::NonExistentSchemaException } 20 | let(:error_message) { 'Specified schema does not exist' } 21 | 22 | it 'responds with nil' do 23 | expect { subject }.to raise_error(error, error_message) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/iuliia/translit_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rspec' 4 | 5 | describe Iuliia::Translit do 6 | describe '#translit' do 7 | let(:test_data) do 8 | Dir['lib/schemas/*.json'].map do |schema_file| 9 | file = File.read(schema_file) 10 | data = JSON.parse(file) 11 | schema_name = data['name'] 12 | samples = data['samples'] 13 | 14 | { schema_name => samples } 15 | end.reduce({}, :update) 16 | end 17 | 18 | it 'transliterates strings correctly' do 19 | test_data.each do |schema_name, samples| 20 | pp "Schema #{schema_name}" 21 | 22 | samples.each do |sample| 23 | expect(described_class.new(sample[0], schema_name).translit).to eq(sample[1]) 24 | end 25 | end 26 | end 27 | 28 | context 'with latin chars' do 29 | let(:schema) { 'telegram' } 30 | let(:given) { 'Юлия, съешь ещё этих soft french булок из Vancouver City, да выпей алтайского TEA' } 31 | let(:expected) { 'Iuliia, sesh esce etih soft french bulok iz Vancouver City, da vypei altaiskogo TEA' } 32 | 33 | it 'transliterates strings correctly' do 34 | expect(described_class.new(given, schema).translit).to eq(expected) 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/setup' 4 | require 'iuliia' 5 | 6 | RSpec.configure do |config| 7 | # Enable flags like --only-failures and --next-failure 8 | config.example_status_persistence_file_path = '.rspec_status' 9 | 10 | # Disable RSpec exposing methods globally on `Module` and `main` 11 | config.disable_monkey_patching! 12 | 13 | config.expect_with :rspec do |c| 14 | c.syntax = :expect 15 | end 16 | 17 | config.expose_dsl_globally = true 18 | end 19 | --------------------------------------------------------------------------------