| Module | FeedTools::URI::IDNA |
| In: |
lib/feed_tools/vendor/uri.rb
|
This module handles internationalized domain names. When Ruby has an implementation of nameprep, stringprep, punycode, etc, this module should contain an actual implementation of IDNA instead of returning nil if libidn can‘t be used.
Returns the ascii representation of the label.
# File lib/feed_tools/vendor/uri.rb, line 622
622: def self.to_ascii(label)
623: return nil if label.nil?
624: if self.use_libidn?
625: return IDN::Idna.toASCII(label)
626: else
627: raise NotImplementedError,
628: "There is no available pure-ruby implementation. " +
629: "Install libidn bindings."
630: end
631: end
Returns the unicode representation of the label.
# File lib/feed_tools/vendor/uri.rb, line 634
634: def self.to_unicode(label)
635: return nil if label.nil?
636: if self.use_libidn?
637: return IDN::Idna.toUnicode(label)
638: else
639: raise NotImplementedError,
640: "There is no available pure-ruby implementation. " +
641: "Install libidn bindings."
642: end
643: end
Determines if the libidn bindings are available and able to be used.
# File lib/feed_tools/vendor/uri.rb, line 647
647: def self.use_libidn?
648: if !defined?(@use_libidn) || @use_libidn.nil?
649: begin
650: require 'rubygems'
651: rescue LoadError
652: end
653: begin
654: require 'idn'
655: rescue LoadError
656: end
657: @use_libidn = !!(defined?(IDN::Idna))
658: end
659: return @use_libidn
660: end