Class: Dogo::Url
- Inherits:
-
Object
- Object
- Dogo::Url
- Defined in:
- lib/dogo/url.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .find(id) ⇒ Object
-
.valid?(url) ⇒ Boolean
Check if the given URL is valid, according the the
URI
regular expression.
Instance Method Summary collapse
-
#click! ⇒ Object
Increment the click counter for this URL.
-
#clicks ⇒ Object
Return the clicks for the current URL.
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
Constructor Details
#initialize(url) ⇒ Url
Returns a new instance of Url.
20 21 22 23 |
# File 'lib/dogo/url.rb', line 20 def initialize(url) @url = url load_or_create end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/dogo/url.rb', line 3 def id @id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/dogo/url.rb', line 3 def url @url end |
Class Method Details
.find(id) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/dogo/url.rb', line 13 def self.find(id) key = Dogo.redis.keys("urls:*:#{id}").first return unless key new Dogo.redis.get(key) end |
.valid?(url) ⇒ Boolean
Check if the given URL is valid, according the the URI
regular expression.
7 8 9 |
# File 'lib/dogo/url.rb', line 7 def self.valid?(url) URI::DEFAULT_PARSER.regexp[:ABS_URI] =~ url.to_s end |