Sha256: 859136da453db6bd51a32d9e9c8ffdef70389a3aba1682fcf98d769a45ae571d

Contents?: true

Size: 1.54 KB

Versions: 29

Compression:

Stored size: 1.54 KB

Contents

# encoding:utf-8
#--
# Copyright (C) Bob Aman
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#++


require "idn"

module Addressable
  module IDNA
    def self.punycode_encode(value)
      IDN::Punycode.encode(value.to_s)
    end

     def self.punycode_decode(value)
       IDN::Punycode.decode(value.to_s)
     end

    def self.unicode_normalize_kc(value)
      IDN::Stringprep.nfkc_normalize(value.to_s)
    end

    def self.to_ascii(value)
      value.to_s.split('.', -1).map do |segment|
        if segment.size > 0 && segment.size < 64
          IDN::Idna.toASCII(segment, IDN::Idna::ALLOW_UNASSIGNED)
        elsif segment.size >= 64
          segment
        else
          ''
        end
      end.join('.')
    end

    def self.to_unicode(value)
      value.to_s.split('.', -1).map do |segment|
        if segment.size > 0 && segment.size < 64
          IDN::Idna.toUnicode(segment, IDN::Idna::ALLOW_UNASSIGNED)
        elsif segment.size >= 64
          segment
        else
          ''
        end
      end.join('.')
    end
  end
end

Version data entries

29 entries across 24 versions & 6 rubygems

Version Path
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.13 vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.12.1 vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.11 vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.9 vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb
tdiary-5.0.8 vendor/bundle/gems/addressable-2.5.2/lib/addressable/idna/native.rb