Sha256: 86e5c13a430d2a97819ef147f8e38e4a2d4b29cfcbd9e65b9af07b2952b225ef

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

module PictureFrom
  class SearchEngine

    DEFAULT_RULES = {
      username: [
        { facebook: :picture_from_username },
        { twitter: :picture_from_username },
        { facebook: :picture_from_user_info }
      ],
      email: [
        { gravatar: :picture_from_email },
        { facebook: :picture_from_user_info }
      ],
      user_info: [
        { facebook: :picture_from_user_info }
      ]
    }

    def initialize(keyword_value = '')
      @keyword = Keyword.new(keyword_value)
    end

    def image_url
      default_rules.each do |rule|
        rule.each do |provider, method|
          image_url = initialize_provider(provider).send(method, @keyword.value)
          return image_url if image_url
        end
      end
    end

    private

    def default_rules
      DEFAULT_RULES[@keyword.type]
    end

    def initialize_provider(provider)
      provider_name = "#{provider.capitalize}Picture"
      PictureFrom.const_get(provider_name).new
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picture_from-1.0.0 lib/picture_from/search_engine.rb