ermahgerd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ = ERMAHGERD, RUBY GERMS, MAH FRAVRIT!
2
+
3
+ It had to be done.
4
+
5
+ Ermahgerd is a ruby gem to translate your text from English into
6
+ Ermahgerd-lish, based heavily (so far exclusively) on the "ERMAHGERD
7
+ TRANSLATOR":http://ermahgerd.jmillerdesign.com by J Miller Design.
8
+
9
+ = Installation
10
+
11
+ gem install ermahgerd
12
+
13
+ = Usage
14
+
15
+ ```ruby
16
+ require 'ermahgerd'
17
+ Ermahgerd.translate("Goosebumps") #=> "Gerseberms"
18
+ ```
19
+
20
+
21
+
22
+ var translate = function(word) {
23
+ // Don't translate short words
24
+ if (word.length == 1) {
25
+ return word;
26
+ }
27
+
28
+ // Handle specific words
29
+ switch (word) {
30
+ case 'AWESOME': return 'ERSUM';
31
+ case 'BANANA': return 'BERNERNER';
32
+ case 'BAYOU': return 'BERU';
33
+ case 'FAVORITE':
34
+ case 'FAVOURITE': return 'FRAVRIT';
35
+ case 'GOOSEBUMPS': return 'GERSBERMS';
36
+ case 'LONG': return 'LERNG';
37
+ case 'MY': return 'MAH';
38
+ case 'THE': return 'DA';
39
+ case 'THEY': return 'DEY';
40
+ case 'WE\'RE': return 'WER';
41
+ case 'YOU': return 'U';
42
+ case 'YOU\'RE': return 'YER';
43
+ }
44
+
45
+ // Before translating, keep a reference of the original word
46
+ var originalWord = word;
47
+
48
+ // Drop vowel from end of words
49
+ if (originalWord.length > 2) { // Keep it for short words, like "WE"
50
+ word = word.replace(/[AEIOU]$/, '');
51
+ }
52
+
53
+ // Reduce duplicate letters
54
+ word = word.replace(/[^\w\s]|(.)(?=\1)/gi, '');
55
+
56
+ // Reduce adjacent vowels to one
57
+ word = word.replace(/[AEIOUY]{2,}/g, 'E'); // TODO: Keep Y as first letter
58
+
59
+ // DOWN -> DERN
60
+ word = word.replace(/OW/g, 'ER');
61
+
62
+ // PANCAKES -> PERNKERKS
63
+ word = word.replace(/AKES/g, 'ERKS');
64
+
65
+ // The mean and potatoes: replace vowels with ER
66
+ word = word.replace(/[AEIOUY]/g, 'ER'); // TODO: Keep Y as first letter
67
+
68
+ // OH -> ER
69
+ word = word.replace(/ERH/g, 'ER');
70
+
71
+ // MY -> MAH
72
+ word = word.replace(/MER/g, 'MAH');
73
+
74
+ // FALLING -> FERLIN
75
+ word = word.replace('ERNG', 'IN');
76
+
77
+ // POOPED -> PERPERD -> PERPED
78
+ word = word.replace('ERPERD', 'ERPED');
79
+
80
+ // MEME -> MAHM -> MERM
81
+ word = word.replace('MAHM', 'MERM');
82
+
83
+ // Keep Y as first character
84
+ // YES -> ERS -> YERS
85
+ if (originalWord.charAt(0) == 'Y') {
86
+ word = 'Y' + word;
87
+ }
88
+
89
+ // Reduce duplicate letters
90
+ word = word.replace(/[^\w\s]|(.)(?=\1)/gi, '');
91
+
92
+ // YELLOW -> YERLER -> YERLO
93
+ if ((originalWord.substr(-3) == 'LOW') && (word.substr(-3) == 'LER')) {
94
+ word = word.substr(0, word.length - 3) + 'LO';
95
+ }
96
+
97
+ return word;
98
+ };
@@ -0,0 +1,4 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new
4
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ load "lib/ermahgerd/version.rb"
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'ermahgerd'
5
+ s.version = Ermahgerd::VERSION
6
+
7
+ s.summary = %{
8
+ Translate English into Ermahgerd-lish. ERMAHGERD, I LERV RERBER!
9
+ }.strip
10
+
11
+ s.description = %{
12
+ A Ruby ERMAHGERD translator, based on http://ermahgerd.jmillerdesign.com/.
13
+ }.strip
14
+
15
+ s.files = Dir['lib/**/*.rb'] + Dir['test/**/*.rb'] + %w[
16
+ README.md
17
+ Rakefile
18
+ ermahgerd.gemspec
19
+ ]
20
+
21
+ s.require_path = 'lib'
22
+ s.required_ruby_version = ">= 1.9.2"
23
+
24
+ s.author = "Dan Bernier"
25
+ s.email = "danbernier@gmail.com"
26
+ s.homepage = "https://github.com/danbernier/ermahgerd"
27
+ end
@@ -0,0 +1,81 @@
1
+ module Ermahgerd
2
+
3
+ def self.translate(words)
4
+ words.upcase.gsub(/[A-Z]+/) { |word| translate_word(word) }
5
+ end
6
+
7
+ def self.translate_word(word)
8
+ # Don't translate short words
9
+ return word if word.size == 1
10
+
11
+ # Handle specific words
12
+ dictionary = {
13
+ 'AWESOME' => 'ERSUM',
14
+ 'BANANA' => 'BERNERNER',
15
+ 'BAYOU' => 'BERU',
16
+ 'FAVORITE' => 'FRAVRIT',
17
+ 'FAVOURITE' => 'FRAVRIT',
18
+ 'GOOSEBUMPS' => 'GERSBERMS',
19
+ 'LONG' => 'LERNG',
20
+ 'MY' => 'MAH',
21
+ 'THE' => 'DA',
22
+ 'THEY' => 'DEY',
23
+ 'WE\'RE' => 'WER',
24
+ 'YOU' => 'U',
25
+ 'YOU\'RE' => 'YER'
26
+ }
27
+
28
+ return dictionary[word] if dictionary.key? word
29
+
30
+ # Before translating, keep a reference of the original word
31
+ original_word = word
32
+
33
+ # Drop vowel from end of words. Keep it for short words, like "WE"
34
+ word.sub!(/[AEIOU]$/, '') if original_word.size > 2
35
+
36
+ # Reduce duplicate letters
37
+ word.gsub!(/[^\w]|(.)(?=\1)/, '')
38
+
39
+ # Reduce adjacent vowels to one
40
+ word.gsub!(/[AEIOUY]{2,}/, 'E') # TODO: Keep Y as first letter
41
+
42
+ # DOWN -> DERN
43
+ word.gsub!(/OW/, 'ER')
44
+
45
+ # PANCAKES -> PERNKERKS
46
+ word.gsub!(/AKES/, 'ERKS')
47
+
48
+ # The mean and potatoes: replace vowels with ER
49
+ word.gsub!(/[AEIOUY]/, 'ER') # TODO: Keep Y as first letter
50
+
51
+ # OH -> ER
52
+ word.gsub!(/ERH/, 'ER')
53
+
54
+ #MY -> MAH
55
+ word.gsub!(/MER/, 'MAH')
56
+
57
+ #FALLING -> FERLIN
58
+ word.gsub!('ERNG', 'IN')
59
+
60
+ #POOPED -> PERPERD -> PERPED
61
+ word.gsub!('ERPERD', 'ERPED')
62
+
63
+ #MEME -> MAHM -> MERM
64
+ word.gsub!('MAHM', 'MERM')
65
+
66
+ # Keep Y as first character
67
+ # YES -> ERS -> YERS
68
+ word = 'Y' + word if original_word[0] == 'Y'
69
+
70
+ # Reduce duplicate letters
71
+ word.gsub!(/[^\w]|(.)(?=\1)/, '')
72
+
73
+ # YELLOW -> YERLER -> YERLO
74
+ if original_word.end_with?('LOW') && word.end_with?('LER')
75
+ word.sub!(/LER$/, 'LO')
76
+ end
77
+
78
+ return word
79
+ end
80
+
81
+ end
@@ -0,0 +1,3 @@
1
+ module Ermahgerd
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'ermahgerd'
3
+
4
+ describe Ermahgerd do
5
+
6
+ def trans(src)
7
+ Ermahgerd.translate(src)
8
+ end
9
+
10
+ it 'can translate some basic phrases' do
11
+ trans('Goosebumps, my favorite books!').must_equal 'GERSBERMS, MAH FRAVRIT BERKS!'
12
+ trans('I love chocolate').must_equal 'I LERV CHERCERLERT'
13
+ trans('I love pancakes!').must_equal 'I LERV PERNCERKS!'
14
+ trans('bananas are awesome.').must_equal 'BERNERNERS ER ERSUM.'
15
+ trans('Mashed potatoes, my favorite!').must_equal 'MAHSHERD PERTERTERS, MAH FRAVRIT!'
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ermahgerd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Bernier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Ruby ERMAHGERD translator, based on http://ermahgerd.jmillerdesign.com/.
15
+ email: danbernier@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ermahgerd/version.rb
21
+ - lib/ermahgerd.rb
22
+ - test/test_ermahgerd.rb
23
+ - README.md
24
+ - Rakefile
25
+ - ermahgerd.gemspec
26
+ homepage: https://github.com/danbernier/ermahgerd
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.9.2
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Translate English into Ermahgerd-lish. ERMAHGERD, I LERV RERBER!
50
+ test_files: []