Class: UrlAttribute::Url

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/url_attribute/url.rb

Direct Known Subclasses

NormalizedUrl

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/url_attribute/url.rb', line 7

def uri
  @uri
end

#urlObject (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_sObject



28
29
30
# File 'lib/url_attribute/url.rb', line 28

def to_s
  url.to_s
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/url_attribute/url.rb', line 32

def valid?
  uri.present? && url =~ /^#{URI::regexp}$/
end