Class: Fotolia::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/fotolia/language.rb

Overview

Represents a language at Fotolia. An object of this class may be given to Fotolia::Base#new:

language = Fotolia::Language.new :de
fotolia = Fotolia.new :api_key => 'AAAAA...', :language => language

Most API calls on the fotolia object will deliver translated results then.

Constant Summary collapse

LANGUAGE_IDS =

Translate language code-like symbols to their ids at Fotolia.

{
  :fr => 1,
  :en_us => 2,
  :en_uk => 3,
  :de => 4,
  :es => 5,
  :it => 6,
  :pt_pt => 7,
  :pt_br => 8,
  :jp => 9,
  :pl => 11
}

Instance Method Summary collapse

Constructor Details

#initialize(id_or_lang_sym) ⇒ Language

Returns a new instance of Language.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fotolia/language.rb', line 32

def initialize(id_or_lang_sym)
  if(id_or_lang_sym.is_a?(Symbol))
    raise Fotolia::LanguageNotDefinedError and return nil unless(LANGUAGE_IDS.has_key?(id_or_lang_sym))
    @language_sym = id_or_lang_sym
  else
    raise Fotolia::LanguageNotDefinedError and return nil unless(LANGUAGE_IDS.has_value?(id_or_lang_sym))
    @language_sym = LANGUAGE_IDS.invert[id_or_lang_sym]
  end

  self
end

Instance Method Details

#idObject



54
55
56
# File 'lib/fotolia/language.rb', line 54

def id
  LANGUAGE_IDS[@language_sym]
end

#to_sObject Also known as: to_code



44
45
46
# File 'lib/fotolia/language.rb', line 44

def to_s
  @language_sym.to_s
end

#to_symObject



50
51
52
# File 'lib/fotolia/language.rb', line 50

def to_sym
  @language_sym
end