Class: Validation::Rule::URI
- Inherits:
-
Object
- Object
- Validation::Rule::URI
- Defined in:
- lib/validation/rule/uri.rb
Instance Method Summary collapse
- #error_key ⇒ Object
-
#initialize(parts = [:host]) ⇒ URI
constructor
A new instance of URI.
- #params ⇒ Object
- #valid_value?(uri_string) ⇒ Boolean
Constructor Details
#initialize(parts = [:host]) ⇒ URI
Returns a new instance of URI.
4 5 6 |
# File 'lib/validation/rule/uri.rb', line 4 def initialize(parts=[:host]) @required_parts = parts end |
Instance Method Details
#error_key ⇒ Object
8 9 10 |
# File 'lib/validation/rule/uri.rb', line 8 def error_key :uri end |
#params ⇒ Object
12 13 14 |
# File 'lib/validation/rule/uri.rb', line 12 def params {:required_elements => @required_parts} end |
#valid_value?(uri_string) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/validation/rule/uri.rb', line 16 def valid_value?(uri_string) begin 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 => e return false end end |