alexandria 0.0.1

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,20 @@
1
+ Copyright 2012 Giannis Tsagatakis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ = Alexandria
2
+
3
+ Provides a simple to_greeklish method on strings. The target case fros this
4
+ game is friendly URL's
5
+
6
+ For better results downcase the string first
7
+
8
+ slug = text.mb_chars.downcase.to_greeklish
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Alexandria'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ require 'alexandria/core_ext/string'
2
+ module Alexandria
3
+ end
@@ -0,0 +1,132 @@
1
+ #encoding: utf-8
2
+
3
+ class String
4
+ def to_greeklish
5
+ Greeklish::to_greeklish(self)
6
+ end
7
+ end
8
+
9
+ class Greeklish
10
+ RULES = {
11
+ "άι" => "ai",
12
+ "όι" => "oi",
13
+ "ηύ" => "iv",
14
+
15
+ /[αάᾶᾳἀἄἆὰᾱᾰ]/ => "α",
16
+ /[εέἐὲ]/ => "ε",
17
+ /[ηήῆῃἠὴἥ]/ => "η",
18
+ /[ύϋὐΰῦὑὺῡῠ]/ => "υ",
19
+ /[ώὼῳῶὠὡ]/ => "ω",
20
+ /[όὸ]/ => "ω",
21
+ /[ιί]/ => "ι",
22
+ /[ΐ]/ => "ϊ",
23
+ /[υύ]/ => "υ",
24
+ /[ΆᾺᾼ]/ => "Α",
25
+ /[ΈῈ]/ => "Ε",
26
+ /[ΪΊῚ]/ => "Ι",
27
+ /[ΌῸ]/ => "Ο",
28
+ /[ΫῪΎ]/ => "Υ",
29
+ /[ΏῺῼ]/ => "Ω",
30
+
31
+ # After tonos replacement rules
32
+ "ου" => "u",
33
+ "ει" => "i",
34
+ "αι" => "e",
35
+ "αϊ" => "ai",
36
+ "οι" => "i",
37
+ "υι" => "i",
38
+ "α[ϊΐ]" => "ai",
39
+ "ηυ" => "if",
40
+
41
+
42
+ # the rules for 'αυ'
43
+ # Note that αυ = αφ(af) or αυ = αβ(av)
44
+ /αυ$/ => "af", # at end of word
45
+ /αυ([πτκφθσχ])/ => 'af\1', # single quotes, followed by 'no-sound' letter
46
+ "αυ" => "av", # followed by 'hard' letter or vowel
47
+
48
+ # The rules for "ευ"
49
+ /ευ$/ => "ef", # at end of word
50
+ /ευφ/ => "ef",
51
+ /ευ([πτκθσχ])/ => 'ef\1', # single quotes, followed by 'no-sound' letter
52
+ "ευ" => "ev", # followed by 'hard' letter or vowel
53
+
54
+ # Special 'σ' case
55
+ /σ([βδγζμνρλ])/ => 'z\1',
56
+
57
+ "φγκ" => "fg",
58
+ "γγ" => "ng",
59
+ "γκ" => "ng",
60
+ "γχ" => "nx",
61
+ "γξ" => "nks",
62
+
63
+ "ββ" => "v",
64
+ "κκ" => "k",
65
+ "λλ" => "l",
66
+ "μμ" => "m",
67
+ "νν" => "n",
68
+ "ππ" => "p",
69
+ "ρρ" => "r",
70
+ "ττ" => "t",
71
+
72
+ "Α" => "A",
73
+ "Β" => "B",
74
+ "Γ" => "G",
75
+ "Δ" => "D",
76
+ "Ε" => "E",
77
+ "Ζ" => "Z",
78
+ "Η" => "H",
79
+ "Θ" => "Th",
80
+ "Ι" => "I",
81
+ "Κ" => "K",
82
+ "Λ" => "L",
83
+ "Μ" => "M",
84
+ "Ν" => "N",
85
+ "Ξ" => "Ks",
86
+ "Ο" => "O",
87
+ "Π" => "P",
88
+ "Ρ" => "R",
89
+ "Σ" => "S",
90
+ "Τ" => "T",
91
+ "Υ" => "Y",
92
+ "Φ" => "F",
93
+ "Χ" => "X",
94
+ "Ψ" => "Ps",
95
+ "Ω" => "O",
96
+ "α" => "a",
97
+ "β" => "v",
98
+ "γ" => "g",
99
+ "δ" => "d",
100
+ "ε" => "e",
101
+ "ζ" => "z",
102
+ "η" => "i",
103
+ "θ" => "th",
104
+ "ι" => "i",
105
+ "κ" => "k",
106
+ "λ" => "l",
107
+ "μ" => "m",
108
+ "ν" => "n",
109
+ "ξ" => "ks",
110
+ "ο" => "o",
111
+ "π" => "p",
112
+ "ρ" => "r",
113
+ "σ" => "s",
114
+ "ς" => "s",
115
+ "τ" => "t",
116
+ "υ" => "i",
117
+ "φ" => "f",
118
+ "χ" => "x",
119
+ "ψ" => "ps",
120
+ "ω" => "o",
121
+ "ϊ" => "i",
122
+ }
123
+
124
+
125
+ def self.to_greeklish(text)
126
+ Greeklish::RULES.each do |from,to|
127
+ text = text.gsub(from,to)
128
+ end
129
+ text
130
+ end
131
+
132
+ end
@@ -0,0 +1,3 @@
1
+ module Alexandria
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :alexandria do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,174 @@
1
+ #encoding: utf-8
2
+ require "test/unit"
3
+ require "alexandria"
4
+
5
+ class GreekLishTest <Test::Unit::TestCase
6
+
7
+ def greeklish_me(examples)
8
+ examples.each do |text,greeklish|
9
+ assert_equal greeklish, text.to_greeklish
10
+ end
11
+ end
12
+
13
+ # Words with 'αυ' is hard to get it right
14
+ # "Words with 'αυ'."
15
+ def test_au
16
+ greeklish_me( {
17
+ "ταυ" => "taf",
18
+ "αυθεντικός" => "afthentikos",
19
+ "αύρα" => "avra",
20
+ "αύριο" => "avrio",
21
+ "αύγουστος" => "avgustos",
22
+ "ταυτόχρονα" => "taftoxrona",
23
+ "αυλή" => "avli",
24
+ "αυτός" => "aftos",
25
+ "θαυμάζω" => "thavmazo",
26
+ "παύση" => "pafsi",
27
+ "καύση" => "kafsi",
28
+ "κένταυρος" => "kentavros",
29
+ "αυγό" => "avgo",
30
+ "Παύλος" => "Pavlos",
31
+ "προαυλιο" => "proavlio",
32
+ "θαυμα" => "thavma",
33
+ "τράυμα" => "travma",
34
+ "μαύρος" => "mavros",
35
+ "ταύρος" => "tavros",
36
+ "σαύρα" => "savra",
37
+ })
38
+ end
39
+
40
+ # "Words with 'ευ'."
41
+ def test_eu
42
+ greeklish_me( {
43
+ "ευρώπη" => "evropi",
44
+ "ευφορία" => "eforia",
45
+ "ευχή" => 'efxi',
46
+ "φεύγω" => "fevgo",
47
+ "ρεύμα" => "revma",
48
+ "νεύρα" => "nevra",
49
+ "φυτεύω" => "fitevo",
50
+ "χαζεύω" => "xazevo",
51
+ })
52
+ end
53
+
54
+ # test "Words with double vowels." do
55
+ def test_dd
56
+ greeklish_me( {
57
+ "αηδόνι" => "aidoni",
58
+ "κελαηδάει" => "kelaidai",
59
+ "αϊτός" => 'aitos',
60
+ "γάιδαρο" => "gaidaro",
61
+ "φράουλα" => "fraula",
62
+ "προίκα" => "prika",
63
+ "προϊόν" => "proion",
64
+ })
65
+ end
66
+
67
+ # test "Words with 'σ' that sounds like 'z'." do
68
+ def test_sz
69
+ greeklish_me( {
70
+ "σβούρα" => "zvura",
71
+ "σμήνος" => "zminos",
72
+ "οργανισμός" => "organizmos",
73
+ })
74
+ end
75
+
76
+
77
+ # test "Words with double letters." do
78
+ def test_ddd
79
+ greeklish_me( {
80
+ "σαββάτο" => "savato",
81
+ "αλλού" => "alu",
82
+ "θάλλασα" => 'thalasa',
83
+ "γραμμα" => "grama",
84
+ })
85
+ end
86
+
87
+ # test "Words with 'αι'." do
88
+ def test_ai
89
+ greeklish_me( {
90
+ "αίθουσα" => "ethusa",
91
+ "έπαινος" => "epenos",
92
+ "λαιμός" => "lemos",
93
+ "λερναία" => "lernea",
94
+ "σπουδαίος" => "spudeos",
95
+ "αιτιατική" => "etiatiki",
96
+ })
97
+ end
98
+
99
+ #test "Words with 'ηυ'." do
100
+ def test_hi
101
+ greeklish_me( {
102
+ "εφηύρα" => "efivra",
103
+ "ηυξημένος" => "ifksimenos",
104
+ })
105
+ end
106
+
107
+
108
+ #test "Greeklish examples" do
109
+ def test_misc
110
+ greeklish_me( {
111
+ #"Πάγκαλος" => "Malakas",
112
+ "καλημέρα" => "kalimera",
113
+ "αφγκανιστάν"=> "afganistan",
114
+ "ἥρως" => "iros",
115
+ "βίος" => "vios",
116
+ "γάλα" => "gala",
117
+ "γη" => "gi",
118
+ "δῆμος" => "dimos",
119
+ "ζώνη" => "zoni",
120
+ "θεολογία" => "theologia",
121
+ "καλός" => "kalos",
122
+ "κύκλος" => "kiklos",
123
+ "λεξικό" => "leksiko",
124
+ "ελιά" => "elia",
125
+ "μηχανικός" => "mixanikos",
126
+ "νέος" => "neos",
127
+ "νιότη" => "nioti",
128
+ "ξενοφοβία" => "ksenofovia",
129
+ "πρόγραμμα" => "programa",
130
+ "ρητορική" => "ritoriki",
131
+ "σύστημα" => "sistima",
132
+ "τηλέφωνο" => "tilefono",
133
+ "φαινόμενο" => "fenomeno",
134
+ "χάος" => "xaos",
135
+ "χειρόγραφος" => "xirografos",
136
+ "ψυχοθεραπεία" => "psixotherapia",
137
+ "αγγούρι" => "anguri",
138
+ "συγγραφέας" => "singrafeas",
139
+ "άγγελος" => "angelos",
140
+ "εγκώμιο" => "engomio",
141
+ "εγγενής" => "engenis",
142
+ "εγκυκλοπαίδεια" => "engiklopedia",
143
+ "άγχος" => "anxos",
144
+ "εγχείριση" => "enxirisi",
145
+ "έλεγξα" => "elenksa",
146
+ "εμπάθεια" => "empathia",
147
+ "εντάξει" => "entaksi",
148
+ "τσάι" => "tsai",
149
+ "τζαζ" => "tzaz",
150
+ "αλφάβητο" => "alfavito",
151
+ "ενέργεια" => "energia",
152
+ "ηθική" => "ithiki",
153
+ "ιστορία" => "istoria",
154
+ "υγιεινή" => "igiini",
155
+ "οικονομία" => "ikonomia",
156
+ "υιός" => "ios",
157
+
158
+ "ώρα" => "ora",
159
+
160
+ "ουτοπία" => "utopia",
161
+ "αιγιαλός" => "egialos",
162
+
163
+ "άξιος" => "aksios",
164
+ "πριονοκορδέλα" => "prionokordela",
165
+ "άξενος" => "aksenos",
166
+
167
+ "θάλλασα" => "thalasa",
168
+ "αεροδρόμια" => "aerodromia",
169
+ "υποχρεωμένος" => "ipoxreomenos",
170
+ "σφυρί" => "sfiri",
171
+ "φακοειδής" => "fakoidis"
172
+ })
173
+ end
174
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexandria
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Giannis Tsagatakis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides to_greeklish method for pretty url.
15
+ email:
16
+ - jtsagata@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/alexandria.rb
22
+ - lib/alexandria/core_ext/string.rb
23
+ - lib/alexandria/version.rb
24
+ - lib/tasks/alexandria_tasks.rake
25
+ - MIT-LICENSE
26
+ - Rakefile
27
+ - README.rdoc
28
+ - test/greeklish_test.rb
29
+ homepage: http://github.com/jtsagata/alexandria
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ segments:
42
+ - 0
43
+ hash: -252011412364663816
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ segments:
51
+ - 0
52
+ hash: -252011412364663816
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Toys for the greek language.
59
+ test_files:
60
+ - test/greeklish_test.rb