iuliia 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b104da0c637eac076457e888d30e52f977f2871b80f54cd82f995237ff343338
4
+ data.tar.gz: edba6708b1590c7016749bd65c89f0f01d1514653c620064620fba8749061cd4
5
+ SHA512:
6
+ metadata.gz: b67688c64d902c5507826a3b9da892675bff114450e7cc9039248819a9d95c3904c7851d6698ec2b0e311d2e46ea6740484c163caaed2a2311e1db7138ec0800
7
+ data.tar.gz: b32700393e2f5c510402e9ac22e782d2bc7396e805dcad60e8fec65ac5a7fa5fb83b9364da690eccbb776d408f3e427e3002234afe73d555c4320c3d4fd98212
@@ -0,0 +1,34 @@
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
+
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ with:
26
+ submodules: 'true'
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: 2.6
31
+ - name: Install dependencies
32
+ run: bundle install
33
+ - name: Run tests
34
+ run: bundle exec rake
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,3 @@
1
+ [submodule "lib/schemas"]
2
+ path = lib/schemas
3
+ url = https://github.com/nalgeon/iuliia
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ NewCops: enable
6
+
7
+ Style/Documentation:
8
+ Enabled: false
@@ -0,0 +1,20 @@
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-rb.gemspec'
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: MinBodyLength.
18
+ Style/GuardClause:
19
+ Exclude:
20
+ - 'iiulia-rb.gemspec'
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,16 @@
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.0] - 2020-09-14
8
+ This is the new initial version for gem `iuliia` after renaming it from `iuliia-rb`
9
+
10
+ ## [0.2.0] - 2020-09-14
11
+ Changes:
12
+ * Moved `lib/schemas` to the git submodule `github.com/nalgeon/iuliia`
13
+ * Lazy loading for schemas
14
+
15
+ ## [0.1.0] - 2020-04-30
16
+ ### Initial release
data/Gemfile ADDED
@@ -0,0 +1,8 @@
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-rb.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
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.
@@ -0,0 +1,82 @@
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
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'iuliia'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install iuliia
22
+
23
+ ## Usage
24
+
25
+ Get available schemas (dynamically generated from JSON definitions in `lib/schemas`)
26
+ ```ruby
27
+ Iuliia::Schema.available_schemas
28
+
29
+ [
30
+ ['mvd_310', 'MVD 310-1997 transliteration schema'],
31
+ ['bs_2979', 'British Standard 2979:1958 transliteration schema'],
32
+ ['gost_779_alt', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'],
33
+ ['icao_doc_9303', 'ICAO DOC 9303 transliteration schema'],
34
+ ['mvd_310_fr', 'MVD 310-1997 transliteration schema'],
35
+ ['mvd_782', 'MVD 782-2000 transliteration schema'],
36
+ ['iso_9_1968_alt', 'ISO/R 9:1968 transliteration schema'],
37
+ ['mosmetro', 'Moscow Metro map transliteration schema'],
38
+ ['gost_7034', 'GOST R 7.0.34-2014 transliteration schema'],
39
+ ['gost_16876_alt', 'GOST 16876-71 (aka GOST 1983) transliteration schema'],
40
+ ['gost_52290', 'GOST R 52290-2004 transliteration schema'],
41
+ ['ungegn_1987', 'UNGEGN 1987 V/18 transliteration schema'],
42
+ ['telegram', 'Telegram transliteration schema'],
43
+ ['gost_16876', 'GOST 16876-71 (aka GOST 1983) transliteration schema'],
44
+ ['gost_779', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'],
45
+ ['wikipedia', 'Wikipedia transliteration schema'],
46
+ ['bgn_pcgn', 'BGN/PCGN transliteration schema'],
47
+ ['iso_9_1968', 'ISO/R 9:1968 transliteration schema'],
48
+ ['yandex_money', 'Yandex.Money transliteration schema'],
49
+ ['ala_lc', 'ALA-LC transliteration schema.'],
50
+ ['yandex_maps', 'Yandex.Maps transliteration schema'],
51
+ ['gost_52535', 'GOST R 52535.1-2006 transliteration schema'],
52
+ ['bgn_pcgn_alt', 'BGN/PCGN transliteration schema'],
53
+ ['iso_9_1954', 'ISO/R 9:1954 transliteration schema'],
54
+ ['bs_2979_alt', 'British Standard 2979:1958 transliteration schema'],
55
+ ['scientific', 'Scientific transliteration schema'],
56
+ ['ala_lc_alt', 'ALA-LC transliteration schema.']
57
+ ]
58
+ ```
59
+
60
+ Pick one and transliterate
61
+
62
+ ```ruby
63
+ Iuliia.translit('Юлия, съешь ещё этих мягких французских булок из Йошкар-Олы, да выпей алтайского чаю', schema: 'mvd_782')
64
+
65
+ "Yuliya, syesh' eshche etikh myagkikh frantsuzskikh bulok iz Yoshkar-Oly, da vypey altayskogo chayu"
66
+ ```
67
+
68
+ ## TODO
69
+
70
+ * ~~Add documentation~~
71
+ * Maybe some more specs
72
+ * Implement reverse translit (not available for all schemas though): https://github.com/adnikiforov/iuliia-rb/issues/3
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,15 @@
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__)
@@ -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,42 @@
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
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler'
37
+ spec.add_development_dependency 'rake'
38
+ spec.add_development_dependency 'rspec'
39
+ spec.add_development_dependency 'rubocop'
40
+
41
+ spec.add_dependency 'json'
42
+ end
@@ -0,0 +1,8 @@
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'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ class << self
5
+
6
+ # Translit cyrillic string to latin representation
7
+ # @param string [String]
8
+ # @param schema [Iuliia::Schema]
9
+ # @return [String]
10
+ def translit(string, schema:)
11
+ Iuliia::Translit.new(string, schema).translit
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ module Schema
5
+ class << self
6
+
7
+ # Fetch schema by schema name
8
+ # @param schema_name [String]
9
+ # @return [Iuliia::Schema]
10
+ def [](schema_name)
11
+ schemas[schema_name]
12
+ end
13
+
14
+ alias schema []
15
+
16
+ # Return list of available schemas
17
+ # @return [Array<Iuliia::Schema]>]
18
+ def available_schemas
19
+ load_schemas.transform_values(&:description).to_a
20
+ end
21
+
22
+ private
23
+
24
+ def schemas
25
+ @schemas ||= Hash.new { |h, k| h[k] = load_schema(k) }
26
+ end
27
+
28
+ def load_schema(name)
29
+ JSON.parse(File.read("lib/schemas/#{name}.json"), object_class: OpenStruct, symbolize_names: true)
30
+ end
31
+
32
+ def load_schemas
33
+ Dir['lib/schemas/*.json'].map do |file|
34
+ schema = load_schema(File.basename(file, '.json'))
35
+ [schema.name, schema]
36
+ end.to_h
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ class Translit
5
+ ENDING_LENGTH = 2
6
+
7
+ # Initialize transliterator engine with string and schema
8
+ # @param string [String]
9
+ # @param schema [Iuliia::Schema]
10
+ # @return [Iuliia::Translit]
11
+ def initialize(string, schema)
12
+ @string = string
13
+ @schema = Iuliia::Schema.schema(schema)
14
+ end
15
+
16
+ # Translit cyrillic string to latin representation
17
+ # @return [String]
18
+ def translit
19
+ string.split(/\b/).map { |chunk| translit_chunk(chunk) }.join
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :string, :schema
25
+
26
+ def translit_chunk(chunk)
27
+ return chunk unless /\p{l}+/.match?(chunk)
28
+
29
+ stem, ending = split_word(chunk)
30
+
31
+ return translit_stem(chunk) if ending.empty?
32
+
33
+ translited_ending = schema.ending_mapping&.dig(ending)
34
+ return translit_stem(chunk) if translited_ending.nil?
35
+
36
+ translited_stem = translit_stem(stem)
37
+
38
+ [translited_stem, translited_ending].join
39
+ end
40
+
41
+ def translit_stem(stem)
42
+ translited_stem = stem.chars.each_with_index.map do |char, index|
43
+ translit_char(stem.chars, char, index)
44
+ end
45
+
46
+ camelcase(translited_stem.join)
47
+ end
48
+
49
+ def translit_char(chars, char, index)
50
+ translited_char = translit_prev(chars, index)
51
+ translited_char = translit_next(chars, index) if translited_char.nil?
52
+ translited_char = schema.mapping[char.downcase] if translited_char.nil?
53
+
54
+ upcase?(char) ? translited_char.upcase : translited_char
55
+ end
56
+
57
+ def translit_prev(chars, index)
58
+ prev_char = if index.positive?
59
+ chars[index - 1..index].join.downcase
60
+ else
61
+ chars[index].downcase
62
+ end
63
+
64
+ schema.prev_mapping&.dig(prev_char)
65
+ end
66
+
67
+ def translit_next(chars, index)
68
+ next_char = chars[index..index + 1].join.downcase
69
+ schema.next_mapping&.dig(next_char)
70
+ end
71
+
72
+ def split_word(word)
73
+ if word.length <= ENDING_LENGTH
74
+ [word, '']
75
+ else
76
+ ending = word.length > ENDING_LENGTH ? word[-ENDING_LENGTH..-1] : ''
77
+ stem = word[0..(word.length - ENDING_LENGTH - 1)] || word
78
+
79
+ [stem, ending]
80
+ end
81
+ end
82
+
83
+ def upcase?(char)
84
+ /[[:upper:]]/.match(char)
85
+ end
86
+
87
+ def camelcase(string)
88
+ return string unless upcase?(string[0])
89
+
90
+ string = string.downcase
91
+ string[0] = string[0].capitalize
92
+ string
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iuliia
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Nikiforov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - a.d.nikiforov@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/spec.yml"
91
+ - ".gitignore"
92
+ - ".gitmodules"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".rubocop_todo.yml"
96
+ - ".travis.yml"
97
+ - CHANGELOG.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - iiulia-rb.gemspec
105
+ - lib/iuliia.rb
106
+ - lib/iuliia/iuliia.rb
107
+ - lib/iuliia/schema.rb
108
+ - lib/iuliia/translit.rb
109
+ - lib/iuliia/version.rb
110
+ homepage: https://github.com/adnikiforov/iuliia-rb
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ homepage_uri: https://github.com/adnikiforov/iuliia-rb
115
+ source_code_uri: https://github.com/adnikiforov/iuliia-rb
116
+ changelog_uri: https://github.com/adnikiforov/iuliia-rb/blob/master/CHANGELOG.md
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.1.4
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Russian transliteration using nalgeon/iuliia schemas
136
+ test_files: []