Sha256: e7b7420528d8d574af06b9cfe0619e7260ca8ac8c26de3307d3da3dc24d1c732

Contents?: true

Size: 588 Bytes

Versions: 13

Compression:

Stored size: 588 Bytes

Contents

require 'apple-news/behaviors/base'
Dir["#{File.dirname(__FILE__)}/behaviors/*.rb"].each { |path| require path }

module AppleNews
  module Behavior
    extend self

    def factory(data)
      return if data.nil?
      
      behaviors.each do |behavior|
        if behavior.type == data[:type]
          return behavior.new(data)
        end
      end

      nil
    end

    private

    def behaviors
      @behaviors ||= self.constants.
        map { |const| self.const_get(const) }.
        select { |const| const.name.demodulize != "Base" && const.is_a?(Class) }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
apple-news-0.5.1 lib/apple-news/behavior.rb
apple-news-0.5.0 lib/apple-news/behavior.rb
apple-news-0.4.2 lib/apple-news/behavior.rb
apple-news-0.4.1 lib/apple-news/behavior.rb
apple-news-0.4.0 lib/apple-news/behavior.rb
apple-news-0.3.1 lib/apple-news/behavior.rb
apple-news-0.3.0 lib/apple-news/behavior.rb
apple-news-0.2.5 lib/apple-news/behavior.rb
apple-news-0.2.4 lib/apple-news/behavior.rb
apple-news-0.2.3 lib/apple-news/behavior.rb
apple-news-0.2.2 lib/apple-news/behavior.rb
apple-news-0.2.1 lib/apple-news/behavior.rb
apple-news-0.2.0 lib/apple-news/behavior.rb