Class: Shortie::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/shortie/service.rb

Constant Summary collapse

@@services =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



20
21
22
# File 'lib/shortie/service.rb', line 20

def key
  @key
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/shortie/service.rb', line 20

def name
  @name
end

#shortenerObject

Returns the value of attribute shortener.



20
21
22
# File 'lib/shortie/service.rb', line 20

def shortener
  @shortener
end

Class Method Details

.allObject

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