Sha256: cb407b4e82fed540e670322b60e62d6a74fbaab86bf83078bd76c6d041ec71c1

Contents?: true

Size: 751 Bytes

Versions: 5

Compression:

Stored size: 751 Bytes

Contents

module Nearmiss
  module Util
    def url_encode(hash)
      hash.to_a.map {|p| p.map {|e| CGI.escape get_string(e)}.join '='}.join '&'
    end

    def get_string(obj)
      if obj.respond_to?(:strftime)
        obj.strftime('%Y-%m-%d')
      else
        obj.to_s
      end
    end

    # Validate if argument is a UUID 
    #
    # @param uuid [String] the string to test against
    # @return [Boolean]
    # @example
    #   Nearmiss.uuid?("31817811-dce4-48c4-aa5f-f49603c5abee") => true
    #   Nearmiss.uuid?("test@gmail.com") => false
    #
    def uuid?(uuid)
      return true if uuid =~ /\A[\da-f]{32}\z/i
      return true if
        uuid =~ /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i
      return false
    end


  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nearmiss-ruby-1.0.4 lib/nearmiss-ruby/util.rb
nearmiss-ruby-1.0.3 lib/nearmiss-ruby/util.rb
nearmiss-ruby-1.0.2 lib/nearmiss-ruby/util.rb
nearmiss-ruby-1.0.1 lib/nearmiss-ruby/util.rb
nearmiss-ruby-1.0.0 lib/nearmiss-ruby/util.rb