Class: NameTranslationParameters
- Inherits:
-
Object
- Object
- NameTranslationParameters
- Defined in:
- lib/name_translation_parameters.rb
Overview
This class encapsulates parameters that are needed for name-translation in Rosette API.
Instance Attribute Summary collapse
-
#entity_type ⇒ Object
Name's entity type (PERSON, LOCATION, ORGANIZATION) (optional).
-
#genre ⇒ Object
genre to categorize the input data.
-
#name ⇒ Object
Name to translate.
-
#rosette_options ⇒ Object
Rosette API options (optional, should be a hash).
-
#source_language_of_origin ⇒ Object
ISO 693-3 code of the name's native language the name originates in (optional).
-
#source_language_of_use ⇒ Object
ISO 693-3 code of the name's language of use (optional).
-
#source_script ⇒ Object
ISO 15924 code of the name's script (optional).
-
#target_language ⇒ Object
ISO 639-3 code of the translation language.
-
#target_scheme ⇒ Object
Transliteration scheme for the translation (optional).
-
#target_script ⇒ Object
ISO 15924 code of name's script (optional).
Instance Method Summary collapse
-
#initialize(name, target_language, options = {}) ⇒ NameTranslationParameters
constructor
:notnew:.
-
#load_params ⇒ Object
Converts this class to Hash with its keys in lower CamelCase.
-
#to_hash ⇒ Object
Converts this class to Hash.
-
#validate_params ⇒ Object
Validates the parameters by checking if rosette_options is an instance of a Hash.
Constructor Details
#initialize(name, target_language, options = {}) ⇒ NameTranslationParameters
:notnew:
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/name_translation_parameters.rb', line 27 def initialize(name, target_language, = {}) #:notnew: = { entity_type: nil, genre: nil, rosette_options: nil, source_language_of_origin: nil, source_language_of_use: nil, source_script: nil, target_scheme: nil, target_script: nil }.update @name = name @entity_type = [:entity_type] @genre = [:genre] @rosette_options = [:rosette_options] @source_language_of_origin = [:source_language_of_origin] @source_language_of_use = [:source_language_of_use] @source_script = [:source_script] @target_language = target_language @target_scheme = [:target_scheme] @target_script = [:target_script] end |
Instance Attribute Details
#entity_type ⇒ Object
Name's entity type (PERSON, LOCATION, ORGANIZATION) (optional)
7 8 9 |
# File 'lib/name_translation_parameters.rb', line 7 def entity_type @entity_type end |
#genre ⇒ Object
genre to categorize the input data
9 10 11 |
# File 'lib/name_translation_parameters.rb', line 9 def genre @genre end |
#name ⇒ Object
Name to translate
11 12 13 |
# File 'lib/name_translation_parameters.rb', line 11 def name @name end |
#rosette_options ⇒ Object
Rosette API options (optional, should be a hash)
13 14 15 |
# File 'lib/name_translation_parameters.rb', line 13 def @rosette_options end |
#source_language_of_origin ⇒ Object
ISO 693-3 code of the name's native language the name originates in (optional)
15 16 17 |
# File 'lib/name_translation_parameters.rb', line 15 def source_language_of_origin @source_language_of_origin end |
#source_language_of_use ⇒ Object
ISO 693-3 code of the name's language of use (optional)
17 18 19 |
# File 'lib/name_translation_parameters.rb', line 17 def source_language_of_use @source_language_of_use end |
#source_script ⇒ Object
ISO 15924 code of the name's script (optional)
19 20 21 |
# File 'lib/name_translation_parameters.rb', line 19 def source_script @source_script end |
#target_language ⇒ Object
ISO 639-3 code of the translation language
21 22 23 |
# File 'lib/name_translation_parameters.rb', line 21 def target_language @target_language end |
#target_scheme ⇒ Object
Transliteration scheme for the translation (optional)
23 24 25 |
# File 'lib/name_translation_parameters.rb', line 23 def target_scheme @target_scheme end |
#target_script ⇒ Object
ISO 15924 code of name's script (optional)
25 26 27 |
# File 'lib/name_translation_parameters.rb', line 25 def target_script @target_script end |
Instance Method Details
#load_params ⇒ Object
Converts this class to Hash with its keys in lower CamelCase.
Returns the new Hash.
60 61 62 63 64 65 |
# File 'lib/name_translation_parameters.rb', line 60 def load_params validate_params to_hash.select { |_key, value| value } .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } .to_h end |
#to_hash ⇒ Object
Converts this class to Hash.
Returns the new Hash.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/name_translation_parameters.rb', line 70 def to_hash { entity_type: @entity_type, genre: @genre, name: @name, options: @rosette_options, source_language_of_origin: @source_language_of_origin, source_language_of_use: @source_language_of_use, source_script: @source_script, target_language: @target_language, target_scheme: @target_scheme, target_script: @target_script } end |
#validate_params ⇒ Object
Validates the parameters by checking if rosette_options is an instance of a Hash.
51 52 53 54 55 |
# File 'lib/name_translation_parameters.rb', line 51 def validate_params if @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end |