File: uri.rb

package info (click to toggle)
ruby-valid 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: ruby: 309; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Validation
  module Rule
    class URI
      def initialize(parts=[:host])
        @required_parts = parts
      end

      def error_key
        :uri
      end

      def params
        {:required_elements => @required_parts}
      end

      def valid_value?(uri_string)
        return true if uri_string.nil?

        uri = URI(uri_string)
        @required_parts.each do |part|
          if uri.send(part).nil? || uri.send(part).empty?
            return false
          end
        end
        true
      rescue ::URI::InvalidURIError
        return false
      end
    end
  end
end