Class: Wookie::Dialect::Simple
- Defined in:
- lib/wookie/dialects/simple.rb
Overview
A simple wookie dialect found on the net. Works case insensitive (i.e. any string to be translated will be converted to downcase).
Constant Summary collapse
- LOOKUP =
The basic lookup table.
{ 'a' => 'ra', 'b' => 'rh', 'c' => 'oa', 'd' => 'wa', 'e' => 'wo', 'f' => 'ww', 'g' => 'rr', 'h' => 'ac', 'i' => 'ah', 'j' => 'sh', 'k' => 'or', 'l' => 'an', 'm' => 'sc', 'n' => 'wh', 'o' => 'oo', 'p' => 'ak', 'q' => 'rq', 'r' => 'rc', 's' => 'c', 't' => 'ao', 'u' => 'hu', 'v' => 'ho', 'w' => 'oh', 'x' => 'k', 'y' => 'ro', 'z' => 'uf' }.freeze
- SHORT_CODES =
A short code is defined by a length of 1 of a lookup value.
LOOKUP.map{|_,v| v if v.length == 1 }.compact.sort.join
Instance Method Summary collapse
-
#from_wookie(str) ⇒ String
Translates a wookiespeak string to english.
-
#to_wookie(str) ⇒ String
Translates an english string to wookiespeack.
Methods inherited from Base
Instance Method Details
#from_wookie(str) ⇒ String
Translates a wookiespeak string to english.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/wookie/dialects/simple.rb', line 38 def from_wookie(str) chars = str.downcase.split('') lookup = Hash[ LOOKUP.to_a.map(&:reverse) ] english = '' offset = 0 while offset < chars.length cur = chars[offset] nxt = chars[offset,2].join if lookup.keys.include?(cur) english << lookup[cur] elsif lookup.keys.include?(nxt) english << lookup[nxt] offset += 1 else english << cur end offset += 1 end english end |