class NameParameter
This class represents an entity name in Analytics API.
Constants
- VALID_GENDERS
Attributes
Name’s entity type (PERSON, LOCATION, ORGANIZATION) (optional)
Name’s gender (male, female, nonbinary) (optional)
ISO 639-3 code of the name’s language (optional)
ISO 15924 code of the name’s script (optional)
Name to be analyzed
Public Instance Methods
Source
# File name_parameter.rb, line 46 def load_param to_hash .select { |_key, value| value } .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) } end
Converts this class to Hash with its keys in lower CamelCase.
Returns the new Hash.
Source
# File name_parameter.rb, line 55 def to_hash { entity_type: @entity_type, language: @language, script: @script, gender: @gender, text: @text } end
Converts this class to Hash.
Returns the new Hash.
Source
# File name_parameter.rb, line 34 def validate_gender return if @gender.nil? normalized = @gender.to_s.downcase return if VALID_GENDERS.include?(normalized) raise ArgumentError.new("gender must be one of: #{VALID_GENDERS.join(', ')}") end
Protected Instance Methods
Source
# File name_parameter.rb, line 18 def initialize(text, options = {}) # :notnew: options = { entity_type: nil, language: nil, script: nil, gender: nil }.update options @text = text @entity_type = options[:entity_type] @language = options[:language] @script = options[:script] @gender = options[:gender] validate_gender end