Class: SmartyStreets::InternationalStreet::LanguageMode

Inherits:
Object
  • Object
show all
Defined in:
lib/smartystreets_ruby_sdk/international_street/language_mode.rb

Overview

A closed set of valid Language values, the closest Ruby equivalent to an enum: a fixed set of frozen instances rather than an arbitrary string.

Constant Summary collapse

NATIVE =
new('native')
LATIN =
new('latin')
ALL =
[NATIVE, LATIN].freeze

Class Method Summary collapse

Class Method Details

.from_value(value) ⇒ Object

Resolves a LanguageMode instance or a raw value (eg. from user input or config) into a LanguageMode, matching 'native'/'latin' regardless of case.



15
16
17
18
19
20
21
22
23
# File 'lib/smartystreets_ruby_sdk/international_street/language_mode.rb', line 15

def self.from_value(value)
  return value if value.is_a?(LanguageMode)

  match = ALL.find { |mode| mode.value.casecmp?(value.to_s) }
  raise SmartyStreets::UnprocessableEntityError,
        "invalid Language value; must be unset, 'native', or 'latin' (case-insensitive)" if match.nil?

  match
end