Sha256: 3343aea71b952b90432cbb787f67041847ca0920e70d5b1d4316bb4a4c6c5812

Contents?: true

Size: 908 Bytes

Versions: 3

Compression:

Stored size: 908 Bytes

Contents

require 'cgi'
require 'java'
require 'uri'

java_package 'jp.ys.mia.norikra.udf'

class UriParser
  @@elements = {
      :scheme => 0,
      :userinfo => 1,
      :host => 2,
      :port => 3,
      :path => 5,
      :opaque => 6,
      :query => 7,
      :fragment => 8
  }

  def self.split_uri(uri, element_key)
    element_key = element_key.to_sym
    unless @@elements.has_key?(element_key)
      return nil
    end

    begin
      parsed_uri = URI.split(uri)
    rescue URI::InvalidURIError => e
      return nil
    end

    result = parsed_uri[@@elements[element_key]]
    if result.nil?
      ''
    else
      result
    end
  end

  def self.split_query(query_text, key)
    query = CGI::parse(query_text)

    unless query.has_key?(key)
      return nil
    end

    case query[key].length
    when 0 then
      ''
    when 1 then
      query[key][0]
    else
      query[key]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
norikra-udf-uri_parser-0.1.2-java lib/esper_plugin/uri_parser.rb
norikra-udf-uri_parser-0.1.1-java lib/esper_plugin/uri_parser.rb
norikra-udf-uri_parser-0.1.0-java lib/esper_plugin/uri_parser.rb