Sha256: 0df0ec308b3404d4b04e7a6a3e18f6a4c2361e389ece08e48a4e93a08f55b330

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# -*- coding: utf-8 -*-
#
# @file 
# @brief
# @author ongaeshi
# @date   2011/07/13

require 'rubygems'
require 'rack'
include Rack::Utils

module CodeStock
  class Mkurl
    def initialize(path, params)
      @path = escape_path(path)
      @params = params
    end

    def inherit_query_shead_offset
      create_url(query_param(true, true, true))
    end

    def inherit_query_shead
      create_url(query_param(true, true, false))
    end

    def inherit_shead
      create_url(query_param(false, true, false))
    end

    private

    def escape_path(src)
      escape(src).gsub("%2F", '/')
    end

    def create_url(qp)
      if (qp == "")
        @path
      else
        "#{@path}?#{qp}"
      end
    end

    def query_param(query_inherit, shead_inherit, offset_inherit)
      qparam = []
      qparam << "query=#{escape(@params[:query])}" if (query_inherit and @params[:query])
      qparam << "shead=#{escape(@params[:shead])}" if (shead_inherit and @params[:shead])
      qparam << "offset=#{escape(@params[:offset])}" if (offset_inherit and @params[:offset])
      qparam.join('&')
    end
  end
end



Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codestock-0.1.4 lib/codestock/cdweb/lib/mkurl.rb
codestock-0.1.3 lib/codestock/cdweb/lib/mkurl.rb