greeklish_iso843 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8a9b1c75a4cdfe88d93923e74db0df32b6919c0baf57bc5d926e0335e523e3f
4
+ data.tar.gz: d6faf9868e79e861e61e4d0945deb58293a482b473aacc9cc647a4d3d908b48b
5
+ SHA512:
6
+ metadata.gz: 1c758ab1affd37f13dbdfacd79fac463a6f123dcff40053703477922ee347293d85c4ec8f2d837533f944bf7afd728b52fd27f1a12ca7008c9ec3d903e70e792
7
+ data.tar.gz: adbcf58e1273386cd5e10ece84ec549bbd9907d3200ca84b4f9da42ae8659c92e686badbe32e8e2df9b60439d5dcac2c33419649e9509c82975a9f7c6c08c798
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
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][] and this project adheres to
6
+ [Semantic Versioning][].
7
+
8
+ ## [Unreleased][]
9
+
10
+ ## 0.1.0 - 2021-03-04
11
+
12
+ Initial release.
13
+
14
+ [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
15
+ [Semantic Versioning]: http://semver.org/spec/v2.0.0.html
16
+ [Unreleased]: https://github.com/agorf/feedigest/compare/0.1.0...HEAD
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2021 Angelos Orfanakos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # greeklish_iso843
2
+
3
+ A [Ruby][] library that converts Greek text to [Greeklish][], conforming to the
4
+ [ISO 843][] (ELOT 743) standard [used by the Greek State][state].
5
+
6
+ [Ruby]: https://www.ruby-lang.org/en/
7
+ [Greeklish]: https://en.wikipedia.org/wiki/Greeklish
8
+ [ISO 843]: https://www.iso.org/standard/5215.html
9
+ [state]: http://www.passport.gov.gr/passports/GrElotConverter/GrElotConverter.html
10
+
11
+ ## Installation
12
+
13
+ As a [Gem][]:
14
+
15
+ ```sh
16
+ gem install greeklish_iso843
17
+ ```
18
+
19
+ [Gem]: https://rubygems.org/gems/greeklish_iso843/
20
+
21
+ ## Use
22
+
23
+ Require the library in your code:
24
+
25
+ ```ruby
26
+ require 'greeklish_iso843'
27
+ ```
28
+
29
+ Then you can use it to convert text:
30
+
31
+ ```ruby
32
+ GreeklishIso843::Converter.convert("Μπάμπης") # => "Bampis"
33
+ GreeklishIso843::Converter.convert("Άγγελος") # => "Angelos"
34
+ GreeklishIso843::Converter.convert("Ευάγγελος") # => "Efangelos"
35
+ ```
36
+
37
+ Alternatively, you can require the `String` core extension for more convenience:
38
+
39
+ ```ruby
40
+ require 'greeklish_iso843/core_ext/string'
41
+ ```
42
+
43
+ Then you can use it to convert text:
44
+
45
+ ```ruby
46
+ "Μπάμπης".to_greeklish # => "Bampis"
47
+ "Άγγελος".to_greeklish # => "Angelos"
48
+ "Ευάγγελος".to_greeklish # => "Efangelos"
49
+ ```
50
+
51
+ There's also a command line utility that accepts Greek text from the standard
52
+ input and prints the corresponding Greeklish text to the standard output:
53
+
54
+ ```sh
55
+ $ greeklish_iso843
56
+ Μπάμπης
57
+ Άγγελος
58
+ Ευάγγελος
59
+ ^D
60
+ Bampis
61
+ Angelos
62
+ Efangelos
63
+ $
64
+ ```
65
+
66
+ Note: `^D` represents the EOF (End Of File) character, emitted with `Ctrl-D`.
67
+
68
+ ## To-do
69
+
70
+ - Tests 😅
71
+
72
+ ## License
73
+
74
+ [MIT](https://github.com/agorf/greeklish_iso843/blob/master/LICENSE.txt)
75
+
76
+ ## Author
77
+
78
+ [Angelos Orfanakos](https://angelos.dev/)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'greeklish_iso843'
4
+
5
+ begin
6
+ print GreeklishIso843::Converter.convert($stdin.read)
7
+ rescue Interrupt # Ctrl-C
8
+ puts
9
+ end
@@ -0,0 +1,3 @@
1
+ module GreeklishIso843; end
2
+
3
+ require 'greeklish_iso843/converter'
@@ -0,0 +1,131 @@
1
+ class GreeklishIso843::Converter
2
+ GREEK_UPPER = 'ΑΆΒΓΔΕΈΖΗΉΘΙΊΪΚΛΜΝΞΟΌΠΡΣΤΥΎΫΦΧΨΩΏ'.freeze
3
+
4
+ GREEK_LOWER = 'αάβγδεέζηήθιίϊΐκλμνξοόπρσςτυύϋΰφχψωώ'.freeze
5
+
6
+ REPLACEMENTS = {
7
+ 'αι' => 'ai',
8
+ 'αί' => 'ai',
9
+ 'οι' => 'oi',
10
+ 'οί' => 'oi',
11
+ 'ου' => 'ou',
12
+ 'ού' => 'ou',
13
+ 'ει' => 'ei',
14
+ 'εί' => 'ei',
15
+ 'ντ' => 'nt',
16
+ 'τσ' => 'ts',
17
+ 'τζ' => 'tz',
18
+ 'γγ' => 'ng',
19
+ 'γκ' => 'gk',
20
+ 'γχ' => 'nch',
21
+ 'γξ' => 'nx',
22
+ 'αυ' => nil,
23
+ 'αύ' => nil,
24
+ 'ευ' => nil,
25
+ 'εύ' => nil,
26
+ 'ηυ' => nil,
27
+ 'ηύ' => nil,
28
+ 'μπ' => nil,
29
+ 'α' => 'a',
30
+ 'ά' => 'a',
31
+ 'β' => 'v',
32
+ 'γ' => 'g',
33
+ 'δ' => 'd',
34
+ 'ε' => 'e',
35
+ 'έ' => 'e',
36
+ 'ζ' => 'z',
37
+ 'η' => 'i',
38
+ 'ή' => 'i',
39
+ 'θ' => 'th',
40
+ 'ι' => 'i',
41
+ 'ί' => 'i',
42
+ 'ϊ' => 'i',
43
+ 'ΐ' => 'i',
44
+ 'κ' => 'k',
45
+ 'λ' => 'l',
46
+ 'μ' => 'm',
47
+ 'ν' => 'n',
48
+ 'ξ' => 'x',
49
+ 'ο' => 'o',
50
+ 'ό' => 'o',
51
+ 'π' => 'p',
52
+ 'ρ' => 'r',
53
+ 'σ' => 's',
54
+ 'ς' => 's',
55
+ 'τ' => 't',
56
+ 'υ' => 'y',
57
+ 'ύ' => 'y',
58
+ 'ϋ' => 'y',
59
+ 'ΰ' => 'y',
60
+ 'φ' => 'f',
61
+ 'χ' => 'ch',
62
+ 'ψ' => 'ps',
63
+ 'ω' => 'o',
64
+ 'ώ' => 'o'
65
+ }.freeze
66
+
67
+ BLANK_REGEXP = /\A[[:space:]]*\z/.freeze
68
+
69
+ attr_reader :text
70
+
71
+ def self.convert(text)
72
+ new(text).convert
73
+ end
74
+
75
+ def initialize(text)
76
+ @text = text
77
+ end
78
+
79
+ def convert
80
+ text.gsub(/#{REPLACEMENTS.keys.join('|')}/i) do |match|
81
+ match_data = Regexp.last_match
82
+ replacement = REPLACEMENTS[match.downcase]
83
+
84
+ if replacement
85
+ greeklish = replacement
86
+ greek = match + match_data.post_match[0].to_s
87
+ elsif match.casecmp?('μπ')
88
+ greeklish =
89
+ if present?(match_data.pre_match) &&
90
+ GREEK_LOWER[match_data.pre_match[0].downcase] &&
91
+ present?(match_data.post_match) &&
92
+ GREEK_LOWER[match_data.post_match[0].downcase]
93
+ 'mp'
94
+ else
95
+ 'b'
96
+ end
97
+ greek = match
98
+ elsif match.casecmp?('τς')
99
+ greeklish = 'ts'
100
+ greek = match
101
+ else
102
+ index = match_data.offset(0)[0]
103
+ greeklish = REPLACEMENTS[match[0].downcase] +
104
+ ('αβγδεζηλιμνορω'[text[index...index + 2].downcase] ? 'v' : 'f')
105
+ greek = match
106
+ end
107
+
108
+ fix_case(greeklish, greek)
109
+ end
110
+ end
111
+
112
+ private def capitalized?(text)
113
+ GREEK_UPPER[text[0]]
114
+ end
115
+
116
+ private def fix_case(greeklish, greek)
117
+ if capitalized?(greek[0])
118
+ if greek.length == 1 || capitalized?(greek[1])
119
+ greeklish.upcase
120
+ else
121
+ greeklish[0].upcase + greeklish[1..-1]
122
+ end
123
+ else
124
+ greeklish
125
+ end
126
+ end
127
+
128
+ private def present?(text)
129
+ text.to_s !~ BLANK_REGEXP
130
+ end
131
+ end
@@ -0,0 +1,7 @@
1
+ require 'greeklish_iso843'
2
+
3
+ class String
4
+ def to_greeklish
5
+ GreeklishIso843::Converter.convert(self)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module GreeklishIso843
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greeklish_iso843
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Angelos Orfanakos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: rubygems@angelos.dev
15
+ executables:
16
+ - greeklish_iso843
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE.txt
22
+ - README.md
23
+ - bin/greeklish_iso843
24
+ - lib/greeklish_iso843.rb
25
+ - lib/greeklish_iso843/converter.rb
26
+ - lib/greeklish_iso843/core_ext/string.rb
27
+ - lib/greeklish_iso843/version.rb
28
+ homepage: https://github.com/agorf/greeklish_iso843
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.1
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.7.6.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Convert Greek text to Greeklish conforming to ISO 843 (ELOT 743)
52
+ test_files: []