Class: UrlAttribute::Url
- Inherits:
-
Object
- Object
- UrlAttribute::Url
- Extended by:
- Forwardable
- Defined in:
- lib/url_attribute/url.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Url
Returns a new instance of Url.
10 11 12 13 14 |
# File 'lib/url_attribute/url.rb', line 10 def initialize(url) @url = url @uri = URI.parse(url) rescue URI::InvalidURIError end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/url_attribute/url.rb', line 7 def uri @uri end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/url_attribute/url.rb', line 7 def url @url end |
Class Method Details
.dump(url) ⇒ Object
17 18 19 20 21 |
# File 'lib/url_attribute/url.rb', line 17 def dump(url) return nil if url.nil? url.to_s end |
.load(url) ⇒ Object
23 24 25 |
# File 'lib/url_attribute/url.rb', line 23 def load(url) url.nil? ? nil : new(url) end |
Instance Method Details
#to_s ⇒ Object
28 29 30 |
# File 'lib/url_attribute/url.rb', line 28 def to_s url.to_s end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/url_attribute/url.rb', line 32 def valid? uri.present? && url =~ /^#{URI::regexp}$/ end |