Sha256: fcd788e60dbd68c6747e3e38bcd382c85594c61c7c081eda3bba5ab7beb16309

Contents?: true

Size: 531 Bytes

Versions: 2

Compression:

Stored size: 531 Bytes

Contents

module Metric
  class Util
    def self.escape(string)
      URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
    end

    def self.build_query_string(object, prefix = nil)
      string = []
      object.each_pair do |key, value|
        k = prefix ? "#{prefix}[#{key}]" : key
        next if value.nil?
        if value.is_a?(Hash)
          string << build_query_string(value, k)
        else
          string << "#{escape(k)}=#{escape(value.to_s)}"
        end
      end
      string.join("&")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metric-0.1.2 lib/metric/util.rb
metric-0.1.1 lib/metric/util.rb