Module: Ronin::Support::Encoding::Punycode

Defined in:
lib/ronin/support/encoding/punycode.rb

Overview

Contains methods for encoding/decoding punycode encoded Strings.

Core-Ext Methods

Since:

  • 1.0.0

Class Method Summary collapse

Class Method Details

.decode(data) ⇒ String

Decodes a punycode String back into unicode.

Examples:

Encoding::Punycode.decode("xn--8ws00zhy3a")
# => "詹姆斯"

Parameters:

  • data (String)

    The punycode String to decode.

Returns:

  • (String)

    The decoded unicode String.

Since:

  • 1.0.0



73
74
75
# File 'lib/ronin/support/encoding/punycode.rb', line 73

def self.decode(data)
  Addressable::IDNA.to_unicode(data)
end

.encode(data) ⇒ String

Encodes a unicode String into punycode.

Examples:

Encoding::Punycode.encode("詹姆斯")
# => "xn--8ws00zhy3a"

Parameters:

  • data (String)

    The unicode String to encode.

Returns:

  • (String)

    The punycode String.

Since:

  • 1.0.0



54
55
56
# File 'lib/ronin/support/encoding/punycode.rb', line 54

def self.encode(data)
  Addressable::IDNA.to_ascii(data)
end