e2sw 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +12 -0
  2. data/lib/e2sw.rb +59 -0
  3. metadata +48 -0
@@ -0,0 +1,12 @@
1
+ ##E2SW
2
+
3
+ Pure Ruby implementation of the Swedish Chef translator. This project was ported from a flex translator written in 1992 by John Hagerman. I've attempted to port it as completely as possible, although certain things are still not working as expected.
4
+
5
+ ##Usage
6
+
7
+ require 'e2sw'
8
+ translated_string = E2SW.to_sw("i like swedish meatballs")
9
+
10
+ Which results in a translated string of.
11
+
12
+ "i leeke-a svedeesh meetbells"
@@ -0,0 +1,59 @@
1
+ class E2SW
2
+ def self.to_sw(string)
3
+ @string = string
4
+ @string.gsub!(/an/,"un")
5
+ @string.gsub!(/An/,"Un")
6
+ @string.gsub!(/au/,"oo")
7
+ @string.gsub!(/Au/,"Oo")
8
+ wc("a","e")
9
+ wc("A","E")
10
+ inw("ew","oo")
11
+ inw_not("e","e-a")
12
+ nw("en","ee")
13
+ niw("e","i")
14
+ niw("E","I")
15
+ inw("f","ff")
16
+ inw("ir","ur")
17
+ inw("i","ee")
18
+ inw("ow","oo")
19
+ niw("o","oo")
20
+ niw("O","Oo")
21
+ niw("tion","shun")
22
+ @string.gsub!(/the( |$)/,"zee\\1")
23
+ @string.gsub!(/The( |$)/,"Zee\\1")
24
+ nw("th","t")
25
+ inw("u","oo")
26
+ @string.gsub!(/v/,"f")
27
+ @string.gsub!(/V/,"F")
28
+ @string.gsub!(/w/,"v")
29
+ @string.gsub!(/W/,"v")
30
+ return @string
31
+ end
32
+
33
+ def self.wc(search,replace)
34
+ @string.gsub!(/#{search}(?=[A-Za-z'])/,replace)
35
+ end
36
+
37
+ def self.nw(search,replace)
38
+ @string.gsub!(/#{search}(?=[^A-Za-z'])/,replace)
39
+ end
40
+
41
+ def self.inw(search,replace)
42
+ @string.gsub!(/(\w+?)#{search}(\w+)?/,"\\1#{replace}\\2")
43
+ end
44
+
45
+ def self.inw_not(search,replace)
46
+ @string.gsub!(/(\w+?)#{search}(?=[^A-Za-z']|$)/,"\\1#{replace}\\2")
47
+ end
48
+
49
+ def self.niw(search,replace)
50
+ if @string =~ /(^| )#{search}/
51
+ @string.gsub!(/(^| )#{search}/,"\\1#{replace}")
52
+ elsif @string =~ /#{search}( |$)/
53
+ unless @string =~ /#{search}{2}/
54
+ puts "im here"
55
+ @string.gsub!(/#{search}( |$)/,"#{replace}\\1")
56
+ end
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: e2sw
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eugene Howe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Based on a flex translator from the early 1990s writted by John Hagerman,
15
+ this library will convert english into mock swedish
16
+ email:
17
+ - eugene@xtreme-computers.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/e2sw.rb
23
+ - README.md
24
+ homepage: http://github.com/ehowe/e2sw
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Convert english into chefspeak
48
+ test_files: []