Module: TagURI

Defined in:
lib/tag_uri.rb,
lib/tag_uri/version.rb

Overview

Implementation of tag URI’s.

Defined Under Namespace

Classes: ArgumentError, Error

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.create(created_at: Time.now, prefix: "", slug:, host:) ⇒ String

Examples:

class Posts < Sequel::Model # or whatever ORM you're using.
end
post = Post.create #…
post.slug # => "this-is-my-first-post"
TagURI.create host: "http://example.com", prefix: "posts", slug: post.slug, created_at: post.created_at

Parameters:

  • opts (Hash)

Returns:

  • (String)


24
25
26
27
28
29
30
31
32
33
# File 'lib/tag_uri.rb', line 24

def self.create( created_at: Time.now, prefix:"", slug:, host: )
  fail ArgumentError if host.nil? || host.empty?
  fail ArgumentError if slug.nil? || slug.empty?
  
  host = "https://#{host}" unless host =~ %r{^.+\://.+$}
  uri = Addressable::URI.parse File.join( host, prefix, slug )
  uri.scheme = "tag"
  uri.host = "#{uri.host},#{created_at.strftime "%F"}:"
  uri.to_s.sub(%r{://}, ":")
end