Class: C3po

Inherits:
Object
  • Object
show all
Includes:
Client, Translator
Defined in:
lib/c3po.rb,
lib/c3po/client.rb,
lib/c3po/version.rb,
lib/c3po/translator.rb,
lib/c3po/translator/bing.rb,
lib/c3po/translator/google.rb,
lib/c3po/translator/result.rb,
lib/c3po/translator/configuration.rb

Defined Under Namespace

Modules: Client, Translator Classes: NoGivenProvider, NoGivenString

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translator

#is, #is?, #languages, #translate

Methods included from Client

#fetch

Constructor Details

#initialize(to_be_translated = nil) ⇒ C3po

Define a translator object.

Examples:

translator = C3po.new('to be translated')
translator.translate(:fr, :en)

Parameters:

  • string (String)

    String on witch we will work

Raises:

Since:

  • 0.0.1



32
33
34
35
36
37
38
39
# File 'lib/c3po.rb', line 32

def initialize(to_be_translated = nil)
  raise NoGivenString if to_be_translated.nil?
  @to_be_translated = to_be_translated
  select_provider
  @base_url = self.class.base_url
  @result = C3po::Translator::Result.new
  @errors = []
end

Class Attribute Details

.base_urlObject

Returns the value of attribute base_url.



43
44
45
# File 'lib/c3po.rb', line 43

def base_url
  @base_url
end

Instance Attribute Details

#adaptorObject (readonly)

Returns the value of attribute adaptor.



20
21
22
# File 'lib/c3po.rb', line 20

def adaptor
  @adaptor
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



20
21
22
# File 'lib/c3po.rb', line 20

def base_url
  @base_url
end

#errorsObject (readonly)

Returns the value of attribute errors.



20
21
22
# File 'lib/c3po.rb', line 20

def errors
  @errors
end

#resultObject (readonly)

Returns the value of attribute result.



20
21
22
# File 'lib/c3po.rb', line 20

def result
  @result
end

#to_be_translatedObject (readonly)

Returns the value of attribute to_be_translated.



20
21
22
# File 'lib/c3po.rb', line 20

def to_be_translated
  @to_be_translated
end

Class Method Details

.configure(&block) ⇒ Object

Define a configure block.

Delegates to C3po::Translator::Configuration

config.provider can be an Array. In this case, provider will be randomly choosen from it.

Examples:

Define the option.

C3po.configure do |config|
  config.provider = :google
  config.google_api_key = "MYAPIKEY"
end

Parameters:

  • block (Proc)

    The block getting called.

Since:

  • 0.0.1



62
63
64
# File 'lib/c3po.rb', line 62

def configure(&block)
  C3po::Translator::Configuration.configure(&block)
end