greeklish_iso843 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +11 -6
- data/bin/greeklish_iso843 +1 -1
- data/lib/greeklish_iso843.rb +1 -1
- data/lib/greeklish_iso843/core_ext/string.rb +1 -1
- data/lib/greeklish_iso843/{converter.rb → greek_text.rb} +43 -33
- data/lib/greeklish_iso843/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4c26155ee5e66d06b9a44cc5a452bcac2ed78a9f5ed889c6ec9540a9fc5853
|
4
|
+
data.tar.gz: 22c733cff1a29127b39a36ca69caa9cd73d96b6e55009ebb017d0fa517484d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c846c9b550c56a8530c232bc4db7d1eb561484d716758e62a23a4dd50956f63a29df91c99410ef7f9b4028f315660c42b21e4607b5200f3a9ea254dd2a2cc2
|
7
|
+
data.tar.gz: 802ac4eef5af569b492991de5316e7390cf2377acd05d04f3dbcacc8b0adba528d9835be250fd34b64231c9d7ef2917e9f6e614c22cb2289e9fae3b6f886417d
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@ The format is based on [Keep a Changelog][] and this project adheres to
|
|
7
7
|
|
8
8
|
## [Unreleased][]
|
9
9
|
|
10
|
+
## [0.3.0][] - 2021-03-06
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Test text conversion thoroughly with over 100 test cases
|
15
|
+
- Change API from `GreeklishIso843::Converter.convert(text)` to
|
16
|
+
`GreeklishIso843::GreekText.to_greeklish(text)`
|
17
|
+
|
10
18
|
## [0.2.0][] - 2021-03-04
|
11
19
|
|
12
20
|
### Changed
|
@@ -25,4 +33,5 @@ Initial release.
|
|
25
33
|
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
|
26
34
|
[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
|
27
35
|
[0.2.0]: https://github.com/agorf/greeklish_iso843/compare/0.1.0...0.2.0
|
28
|
-
[
|
36
|
+
[0.3.0]: https://github.com/agorf/greeklish_iso843/compare/0.2.0...0.3.0
|
37
|
+
[Unreleased]: https://github.com/agorf/greeklish_iso843/compare/0.3.0...HEAD
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# greeklish_iso843
|
1
|
+
# greeklish_iso843 [![Gem](https://img.shields.io/gem/v/greeklish_iso843?color=blue)](https://rubygems.org/gems/greeklish_iso843/) [![RuboCop](https://github.com/agorf/greeklish_iso843/actions/workflows/rubocop.yml/badge.svg)](https://github.com/agorf/greeklish_iso843/actions/workflows/rubocop.yml) [![Tests](https://github.com/agorf/greeklish_iso843/actions/workflows/tests.yml/badge.svg)](https://github.com/agorf/greeklish_iso843/actions/workflows/tests.yml)
|
2
2
|
|
3
3
|
A [Ruby][] library that converts Greek text to [Greeklish][], conforming to the
|
4
4
|
[ISO 843][] (ELOT 743) standard used by the Greek State.
|
@@ -28,10 +28,10 @@ require 'greeklish_iso843'
|
|
28
28
|
Then you can use it to convert text:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
GreeklishIso843::
|
32
|
-
GreeklishIso843::
|
33
|
-
GreeklishIso843::
|
34
|
-
GreeklishIso843::
|
31
|
+
GreeklishIso843::GreekText.to_greeklish("Μπάμπης") # => "Bampis"
|
32
|
+
GreeklishIso843::GreekText.to_greeklish("Άγγελος") # => "Angelos"
|
33
|
+
GreeklishIso843::GreekText.to_greeklish("Ευάγγελος") # => "Evangelos"
|
34
|
+
GreeklishIso843::GreekText.to_greeklish("ξεσκεπάζω την ψυχοφθόρα σας βδελυγμία") # => "xeskepazo tin psychofthora sas vdelygmia"
|
35
35
|
```
|
36
36
|
|
37
37
|
Alternatively, you can require the `String` core extension for more convenience:
|
@@ -59,9 +59,14 @@ $
|
|
59
59
|
|
60
60
|
Note: `^D` represents the EOF (End Of File) character, emitted with `Ctrl-D`.
|
61
61
|
|
62
|
+
## Tests
|
63
|
+
|
64
|
+
You can run the tests with `rake test` or `rake test TESTOPTS='-v'` for a more
|
65
|
+
verbose output.
|
66
|
+
|
62
67
|
## Acknowledgements
|
63
68
|
|
64
|
-
This library was based on [an official implementation in JavaScript][js].
|
69
|
+
This library was based on [an official, buggy implementation in JavaScript][js].
|
65
70
|
|
66
71
|
[js]: http://www.passport.gov.gr/passports/GrElotConverter/GrElotConverter.html
|
67
72
|
|
data/bin/greeklish_iso843
CHANGED
data/lib/greeklish_iso843.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
class GreeklishIso843::
|
1
|
+
class GreeklishIso843::GreekText
|
2
2
|
GREEK_UPPER = 'ΑΆΒΓΔΕΈΖΗΉΘΙΊΪΚΛΜΝΞΟΌΠΡΣΤΥΎΫΦΧΨΩΏ'.freeze
|
3
3
|
|
4
4
|
GREEK_LOWER = 'αάβγδεέζηήθιίϊΐκλμνξοόπρσςτυύϋΰφχψωώ'.freeze
|
5
5
|
|
6
|
+
GREEK_VOWELS = 'αάεέηήιίϊΐοόυύϋΰωώ'.freeze
|
7
|
+
|
8
|
+
GREEK_LETTERS_AFTER_V = "#{GREEK_VOWELS}βγδζλμνρ".freeze
|
9
|
+
|
6
10
|
REPLACEMENTS = {
|
7
11
|
'αι' => 'ai',
|
8
12
|
'αί' => 'ai',
|
@@ -66,48 +70,27 @@ class GreeklishIso843::Converter
|
|
66
70
|
|
67
71
|
REPLACEMENTS_REGEXP = /#{REPLACEMENTS.keys.join('|')}/i.freeze
|
68
72
|
|
69
|
-
BLANK_REGEXP = /\A[[:space:]]*\z/.freeze
|
70
|
-
|
71
73
|
attr_reader :text
|
72
74
|
|
73
|
-
def self.
|
74
|
-
new(text).
|
75
|
+
def self.to_greeklish(text)
|
76
|
+
new(text).to_greeklish
|
75
77
|
end
|
76
78
|
|
77
79
|
def initialize(text)
|
78
80
|
@text = text
|
79
81
|
end
|
80
82
|
|
81
|
-
def
|
83
|
+
def to_greeklish
|
82
84
|
text.gsub(REPLACEMENTS_REGEXP) do |match|
|
83
85
|
match_data = Regexp.last_match
|
84
|
-
greeklish = REPLACEMENTS[match.downcase]
|
85
|
-
prev_char = match_data.pre_match[-1]&.downcase
|
86
86
|
next_char = match_data.post_match[0]&.downcase
|
87
|
+
greeklish = REPLACEMENTS[match.downcase]
|
88
|
+
greek = match
|
87
89
|
|
88
90
|
if greeklish
|
89
91
|
greek = match + next_char.to_s
|
90
|
-
elsif match.casecmp?('μπ')
|
91
|
-
greeklish =
|
92
|
-
if prev_char && GREEK_LOWER[prev_char] &&
|
93
|
-
next_char && GREEK_LOWER[next_char]
|
94
|
-
'mp'
|
95
|
-
else
|
96
|
-
'b'
|
97
|
-
end
|
98
|
-
greek = match
|
99
|
-
elsif match.casecmp?('τς')
|
100
|
-
greeklish = 'ts'
|
101
|
-
greek = match
|
102
92
|
else
|
103
|
-
greeklish =
|
104
|
-
REPLACEMENTS[match[0].downcase] +
|
105
|
-
if next_char && 'αάεέηήιίϊΐοόυύϋΰωώβγδζλμνρ'[next_char]
|
106
|
-
'v'
|
107
|
-
else
|
108
|
-
'f'
|
109
|
-
end
|
110
|
-
greek = match
|
93
|
+
greeklish = convert_to_greeklish(match, match_data, next_char)
|
111
94
|
end
|
112
95
|
|
113
96
|
fix_case(greeklish, greek)
|
@@ -118,10 +101,12 @@ class GreeklishIso843::Converter
|
|
118
101
|
GREEK_UPPER[text[0]]
|
119
102
|
end
|
120
103
|
|
104
|
+
private def lowercase_char?(char)
|
105
|
+
GREEK_LOWER[char]
|
106
|
+
end
|
107
|
+
|
121
108
|
private def fix_case(greeklish, greek)
|
122
|
-
if !capitalized?(greek[0])
|
123
|
-
return greeklish
|
124
|
-
end
|
109
|
+
return greeklish if !capitalized?(greek[0])
|
125
110
|
|
126
111
|
if greek.length == 1 || capitalized?(greek[1])
|
127
112
|
greeklish.upcase
|
@@ -130,7 +115,32 @@ class GreeklishIso843::Converter
|
|
130
115
|
end
|
131
116
|
end
|
132
117
|
|
133
|
-
private def
|
134
|
-
|
118
|
+
private def convert_mp_or_b(prev_char, next_char)
|
119
|
+
if prev_char && lowercase_char?(prev_char) && # *μπ
|
120
|
+
next_char && lowercase_char?(next_char) # and μπ*
|
121
|
+
'mp'
|
122
|
+
else # μπ* or *μπ
|
123
|
+
'b'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
private def convert_v_or_f(next_char)
|
128
|
+
if next_char && GREEK_LETTERS_AFTER_V[next_char]
|
129
|
+
'v'
|
130
|
+
else
|
131
|
+
'f'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private def convert_to_greeklish(match, match_data, next_char)
|
136
|
+
return 'ts' if match.casecmp?('τς')
|
137
|
+
|
138
|
+
if match.casecmp?('μπ')
|
139
|
+
prev_char = match_data.pre_match[-1]&.downcase
|
140
|
+
return convert_mp_or_b(prev_char, next_char)
|
141
|
+
end
|
142
|
+
|
143
|
+
# αυ αύ ευ εύ ηυ ηύ
|
144
|
+
REPLACEMENTS[match[0].downcase] + convert_v_or_f(next_char)
|
135
145
|
end
|
136
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greeklish_iso843
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angelos Orfanakos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: rubygems@angelos.dev
|
@@ -22,8 +22,8 @@ files:
|
|
22
22
|
- README.md
|
23
23
|
- bin/greeklish_iso843
|
24
24
|
- lib/greeklish_iso843.rb
|
25
|
-
- lib/greeklish_iso843/converter.rb
|
26
25
|
- lib/greeklish_iso843/core_ext/string.rb
|
26
|
+
- lib/greeklish_iso843/greek_text.rb
|
27
27
|
- lib/greeklish_iso843/version.rb
|
28
28
|
homepage: https://github.com/agorf/greeklish_iso843
|
29
29
|
licenses:
|