Class: Shortie::Service
- Inherits:
-
Object
- Object
- Shortie::Service
- Defined in:
- lib/shortie/service.rb
Constant Summary collapse
- @@services =
[]
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#shortener ⇒ Object
Returns the value of attribute shortener.
Class Method Summary collapse
-
.all ⇒ Object
Get a list of all services.
-
.find_by_key(key) ⇒ Object
Find a service by key, e.g.
-
.register(key, name, shortener) ⇒ Object
Register a new service by key, name, and shortener, e.g.
Instance Method Summary collapse
-
#initialize(key, name, shortener) ⇒ Service
constructor
A new instance of Service.
-
#shorten(url) ⇒ Object
Shorten a URL.
Constructor Details
#initialize(key, name, shortener) ⇒ Service
22 23 24 |
# File 'lib/shortie/service.rb', line 22 def initialize(key, name, shortener) self.key, self.name, self.shortener = key, name, shortener end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
20 21 22 |
# File 'lib/shortie/service.rb', line 20 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/shortie/service.rb', line 20 def name @name end |
#shortener ⇒ Object
Returns the value of attribute shortener.
20 21 22 |
# File 'lib/shortie/service.rb', line 20 def shortener @shortener end |
Class Method Details
.all ⇒ Object
Get a list of all services.
11 12 13 |
# File 'lib/shortie/service.rb', line 11 def self.all @@services end |
.find_by_key(key) ⇒ Object
Find a service by key, e.g. 'bitly'.
16 17 18 |
# File 'lib/shortie/service.rb', line 16 def self.find_by_key(key) @@services.find { |s| s.key == key } end |
.register(key, name, shortener) ⇒ Object
Register a new service by key, name, and shortener, e.g. register("bitly", "bit.ly", Bitly).
6 7 8 |
# File 'lib/shortie/service.rb', line 6 def self.register(key, name, shortener) @@services << Service.new(key, name, shortener) end |
Instance Method Details
#shorten(url) ⇒ Object
Shorten a URL. This calls the shorten(url) method on the shortener.
27 28 29 |
# File 'lib/shortie/service.rb', line 27 def shorten(url) shortener.shorten(url) end |