Class: Wookie::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/wookie/translator.rb

Overview

Translates a given string either from wookie to english or vice versa.

Instance Method Summary collapse

Constructor Details

#initialize(options = { :dialect => Wookie::Dialect::Simple }) ⇒ Translator

Contructor, defines the dialect (Dialect::Simple by default).

Parameters:

  • options (Hash) (defaults to: { :dialect => Wookie::Dialect::Simple })

    The instance options.

Options Hash (options):



9
10
11
# File 'lib/wookie/translator.rb', line 9

def initialize(options={ :dialect => Wookie::Dialect::Simple })
  @dialect = options[:dialect].new
end

Instance Method Details

#from_wookie(str) ⇒ String

Translates a string from wookiespeak to english using the dialect given to the initializer.

Parameters:

  • str (#to_s)

    The string to be translated.

Returns:

  • (String)

    The english translation.



27
28
29
# File 'lib/wookie/translator.rb', line 27

def from_wookie(str)
  @dialect.from_wookie(str.to_s)
end

#to_wookie(str) ⇒ String

Translates an english string to wookiespeak using the dialect given to the initializer.

Parameters:

  • str (#to_s)

    The string to be translated.

Returns:

  • (String)

    The translated string.



18
19
20
# File 'lib/wookie/translator.rb', line 18

def to_wookie(str)
  @dialect.to_wookie(str.to_s)
end