Sha256: 79393f3cb9e2ed8b4837687a540e571eda9695f8992f24f715f14ca5c46d9ca6

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 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
      nil
    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.1 lib/picture_from/search_engine.rb