0.0
Low commit activity in last 3 years
No release in over a year
Input URL could be either human-readable, or URL-encoded. Two URLs are returned as result: human-readable and URL-encoded.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
~> 3.0
~> 2.6.0

Runtime

~> 0.1.0
 Project Readme

linkhum-url

URLs which users provide could be both in human-readable form and in URL-encoded form. linkhum-url gem parses URLs in any representation and returns both representations: human-readable and URL-encoded.

linkhum-url handles IDNs and Punycode in domain names. Behind the scenes addressable gem is used to handle actual URL parsing.

This is a sister gem to linkhum.

Usage

linkhum-url has only one method: Linkhum::URL.parse(url). It accepts URL in any representation (usually provided by user) and returns Hash with two keys: :human_readable and :url_encoded. Human-readable representation should be displayed to the user, while URL-encoded representation should be used for HTTP queries, HTML embedding etc.

$ irb
2.3.0 :001 > require 'linkhum-url'
 => true
2.3.0 :002 > Linkhum::URL.parse("https://example.org")
 => {:human_readable=>"https://example.org", :url_encoded=>"https://example.org"}
2.3.0 :003 > Linkhum::URL.parse("https://пивбар-хмель.рф/поиск.html?q=пивбар")
 => {:human_readable=>"https://пивбар-хмель.рф/поиск.html?q=пивбар", :url_encoded=>"https://xn----7sbcdsn0agvo0d1e.xn--p1ai/%D0%BF%D0%BE%D0%B8%D1%81%D0%BA.html?q=%D0%BF%D0%B8%D0%B2%D0%B1%D0%B0%D1%80"}
2.3.0 :004 > Linkhum::URL.parse("https://xn--80abcx8ak.xn--p1ai/%D0%BF%D0%BE%D0%B8%D1%81%D0%BA.html?q=%D0%BF%D0%B8%D0%B2%D0%B1%D0%B0%D1%80")
 => {:human_readable=>"https://пивбар-хмель.рф/поиск.html?q=пивбар", :url_encoded=>"https://xn----7sbcdsn0agvo0d1e.xn--p1ai/%D0%BF%D0%BE%D0%B8%D1%81%D0%BA.html?q=%D0%BF%D0%B8%D0%B2%D0%B1%D0%B0%D1%80"}

Install

$ sudo apt-get install libidn11 libidn11-dev  # Ubuntu Xenial
$ sudo apt-get install idn                    # Older Debian/Ubuntu
$ brew install libidn                         # Mac OS X

$ gem install linkhum-url

License

linkhum-url released under MIT License.

Copyright (C) Alexey Makhotkin, 2016-2019.