0.12
No release in over 3 years
Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations, also HTML link elements.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Link Header

Parse and format HTTP link headers (and equivalent HTML link elements) as described in the Web Linking spec.

Description

Converts conforming link headers or HTML link elements to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations.

Installation

bundle add link_header

Usage

require "link_header"

http_link_header = <<~HEADER
  <http://example.com/foo>; rel="self", <http://example.com/>; rel = "up"
HEADER

LinkHeader
  .parse(http_link_header)
  .to_a
#=> [["http://example.com/foo", [["rel", "self"]]], ["http://example.com/", [["rel", "up"]]]]

link_header = LinkHeader.new([
    ["http://example.com/foo", [%w[rel self]]],
    ["http://example.com/", [%w[rel up]]]
])

link_header.to_s
#=> '<http://example.com/foo>; rel="self", <http://example.com/>; rel="up"'

link_header.to_html
#=> '<link href="http://example.com/foo" rel="self">
#    <link href="http://example.com/" rel="up">'

For more see the LinkHeader and LinkHeader::Link classes or example.rb.

Author

Mike Burrows (asplake), email mjb@asplake.co.uk, website positiveincline.com.