Class: Feedbook::Factories::NotifiersFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/feedbook/factories/notifiers_factory.rb

Class Method Summary collapse

Class Method Details

.create(type) ⇒ Notifier

Returns instance of Notifier for given type.

Parameters:

  • type (Symbol/String)

    name of requested notifier

Returns:

  • (Notifier)

    Notifier instance



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/feedbook/factories/notifiers_factory.rb', line 13

def self.create(type)
  case type
  when :null, 'null'
    Notifiers::NullNotifier.instance
  when :twitter, 'twitter'
    Notifiers::TwitterNotifier.instance
  when :facebook, 'facebook'
    Notifiers::FacebookNotifier.instance
  when :irc, 'irc'
    Notifiers::IRCNotifier.instance
  when :mail, 'mail'
    Notifiers::MailNotifier.instance
  else
    if Notifiers.const_defined?("#{type.camelize}Notifier")
      Notifiers.const_get("#{type.camelize}Notifier").instance
    elsif Notifiers.const_defined?("#{type.upcase}Notifier")
      Notifiers.const_get("#{type.upcase}Notifier").instance
    elsif Notifiers.const_defined?("#{type.capitalize}Notifier")
      Notifiers.const_get("#{type.capitalize}Notifier").instance
    else
      puts "notifier #{type} is not supported by Feedbook."
    end
  end
end