Giter Site home page Giter Site logo

url's Introduction

URL

URL is a simple URL parser and construction tool for Ruby. It doesn't follow any RFC, instead, it behaves as you expect.

Background

I wrote this after being frustrated with the URL handling in Ruby's standard library and other gems. I wanted to be able to parse a URL, modify it and then get the modified URL back as a string. I also wanted to be able to join paths and query strings to URLs without having to worry about trailing slashes and question marks.

Installation

Just point to this repository in your Gemfile:

gem "url", "0.0.0.rc1" github: "ingemar/url", tag: "v0.0.0.rc1"

Usage

Initialize a new URL object by parsing a URL string or domain name:

url = URL.parse("http://www.example.com:404/path")
url.to_s # => "http://www.example.com:404/path"
url.port = nil
url.join("/to")
url.join("/nowhere")
url.to_s # => "http://www.example.com/path/to/nowhere"
url.merge(foo: "bar")
url.to_s # => "http://www.example.com/path/to/nowhere?foo=bar"

Advanced usage

Only use these features if you're a seasoned professional.

# Ugly "syntactic sugar" is supported because this is not opinionated code ;pPppPpPPPpp
url = URL["example.com"]
# Join as much as you want for the price of one!
url.join("/path", "to", "nowhere")
# Not providing a protocol will default to 'https'. This code is contemporary.
url.to_s # => "https://example.com/path/to/nowhere"

Alternaives

If you're looking for something that parses URLs in Ruby and Ruby on Rails and behaves erratically but closely conforms to RFC 3986, RFC 3987, and RFC 6570 (level 4), check out addressable. It's probably better tested and has industrywide adoption or something.

Contributing

Bug reports and pull requests are always welcome!

url's People

Contributors

ingemar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.