Class: Dogo::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/dogo/url.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/dogo/url.rb', line 3

def id
  @id
end

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

Returns:

  • (Boolean)


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

def self.valid?(url)
  URI::DEFAULT_PARSER.regexp[:ABS_URI] =~ url.to_s
end

Instance Method Details

#click!Object

Increment the click counter for this URL.



26
27
28
# File 'lib/dogo/url.rb', line 26

def click!
  Dogo.redis.incr(click_key)
end

#clicksObject

Return the clicks for the current URL.



31
32
33
# File 'lib/dogo/url.rb', line 31

def clicks
  Dogo.redis.get(click_key).to_i
end