class NameTranslationParameters

This class encapsulates parameters that are needed for name-translation in Rosette API.

Attributes

entity_type[RW]

Name’s entity type (PERSON, LOCATION, ORGANIZATION) (optional)

genre[RW]

genre to categorize the input data

name[RW]

Name to translate

rosette_options[RW]

Rosette API options (optional, should be a hash)

source_language_of_origin[RW]

ISO 693-3 code of the name’s native language the name originates in (optional)

source_language_of_use[RW]

ISO 693-3 code of the name’s language of use (optional)

source_script[RW]

ISO 15924 code of the name’s script (optional)

target_language[RW]

ISO 639-3 code of the translation language

target_scheme[RW]

Transliteration scheme for the translation (optional)

target_script[RW]

ISO 15924 code of name’s script (optional)

Public Instance Methods

load_params() click to toggle source

Converts this class to Hash with its keys in lower CamelCase.

Returns the new Hash.

# File name_translation_parameters.rb, line 63
def load_params
  validate_params
  to_hash
    .select { |_key, value| value }
    .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
end
to_hash() click to toggle source

Converts this class to Hash.

Returns the new Hash.

# File name_translation_parameters.rb, line 73
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() click to toggle source

Validates the parameters by checking if rosette_options is an instance of a Hash.

# File name_translation_parameters.rb, line 55
def validate_params
  msg = 'rosette_options can only be an instance of a Hash'
  raise BadRequestError.new(msg) if @rosette_options && !(@rosette_options.is_a? Hash)
end

Protected Instance Methods

initialize(name, target_language, options = {}) click to toggle source
# File name_translation_parameters.rb, line 30
def initialize(name, target_language, options = {}) # :notnew:
  options = {
    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 options
  @name = name
  @entity_type = options[:entity_type]
  @genre = options[:genre]
  @rosette_options = options[:rosette_options]
  @source_language_of_origin = options[:source_language_of_origin]
  @source_language_of_use = options[:source_language_of_use]
  @source_script = options[:source_script]
  @target_language = target_language
  @target_scheme = options[:target_scheme]
  @target_script = options[:target_script]
end