Class: JSONSkooma::Validators::IdnHostname

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/validators/idn_hostname.rb

Instance Method Summary collapse

Methods inherited from Base

assert?, call, inherited

Instance Method Details

#call(data) ⇒ Object



8
9
10
11
12
13
# File 'lib/json_skooma/validators/idn_hostname.rb', line 8

def call(data)
  register_opts = data.value.ascii_only? ? {alabel: data.value} : {ulabel: data.value}
  URI::IDNA.register(**register_opts)
rescue URI::IDNA::Error => e
  raise FormatError, "#{data} is not a valid IDN hostname: #{e.message}"
end