Sha256: 916100503f83fc20626694816074f111ba0796ea0ba2b13abe4ffec0d534e582

Contents?: true

Size: 586 Bytes

Versions: 17

Compression:

Stored size: 586 Bytes

Contents

module Twitter
  class Factory
    class << self
      # Construct a new object
      #
      # @param method [Symbol]
      # @param klass [Class]
      # @param attrs [Hash]
      # @raise [IndexError] Error raised when supplied argument is missing a key.
      # @return [Twitter::Base]
      def new(method, klass, attrs = {})
        type = attrs.fetch(method.to_sym)
        const_name = type.gsub(/\/(.?)/) { "::#{Regexp.last_match[1].upcase}" }.gsub(/(?:^|_)(.)/) { Regexp.last_match[1].upcase }
        klass.const_get(const_name.to_sym).new(attrs)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
twitter-5.14.0 lib/twitter/factory.rb
twitter-5.13.0 lib/twitter/factory.rb
twitter-5.12.0 lib/twitter/factory.rb
twitter-5.11.0 lib/twitter/factory.rb
twitter-5.10.0 lib/twitter/factory.rb
twitter-5.9.0 lib/twitter/factory.rb
twitter-5.8.0 lib/twitter/factory.rb
twitter-5.7.1 lib/twitter/factory.rb
twitter-5.7.0 lib/twitter/factory.rb
twitter-5.6.0 lib/twitter/factory.rb
twitter-5.5.1 lib/twitter/factory.rb
twitter-5.5.0 lib/twitter/factory.rb
twitter-5.4.1 lib/twitter/factory.rb
twitter-5.4.0 lib/twitter/factory.rb
twitter-5.3.1 lib/twitter/factory.rb
twitter-5.3.0 lib/twitter/factory.rb
twitter-5.2.0 lib/twitter/factory.rb