Sha256: 45fbe68ba68c387fb5ff08367be606b724836e656c26c703e104bd38ff3823da

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'feedbook/notifiers'
require 'feedbook/core_ext/string'
require 'feedbook/errors/unsupported_notifier_error'

module Feedbook
  module Factories
    class NotifiersFactory

      # Returns instance of Notifier for given type.
      # @param type [Symbol/String] name of requested notifier
      # 
      # @return [Notifier] Notifier instance
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feedbook-1.1.0 lib/feedbook/factories/notifiers_factory.rb