Sha256: afbef1b7ab26337856f0a9de11774d63682937c4ea4d1ad502accd549064e86e

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'public_suffix'
require 'forbes-finder/errors'
require 'forbes-finder/record'
require 'toml'

module ForbesFinder
  class << self
    # Look up a domain name to see if it's the Forbes 2000 list.
    #
    # Returns a hash with the ranking and company name if one is found e.g.
    #   #=> {:rank => 1, :name => 'GitHub'}
    # returns nil if nothing is found.
    def lookup(domain)
      return if domain.nil? or domain.index('.') < 1 or !ranked?(domain)
      domain = cleanse_domain domain
      record = ForbesFinder::Record.new(domain)
    end

    # Verify if a domain name is ranked in the Forbes 2000.

    # Returns true if a file is found matching the domain; false otherwise.
    def ranked?(domain)
      domain = cleanse_domain(domain)
      File.exists?(File.expand_path(__FILE__+"/../data/2012/#{domain}.toml"))
    end

    # Clean the domain of things like 'http(s)://', 'www',
    # '?foo=bar', etc.
    #
    # Return the domain string.
    def cleanse_domain(domain)
      domain.downcase!
      domain = domain.sub(/^https?\:\/\//, '').sub(/^www./,'')
      domain = domain.split("/").first
      domain = domain.split("@").last

      domain = PublicSuffix.parse(domain)
      domain = "#{domain.sld}.#{domain.tld}"
      domain
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
forbes-finder-0.1.2 lib/forbes-finder.rb
forbes-finder-0.1.1 lib/forbes-finder.rb
forbes-finder-0.1.0 lib/forbes-finder.rb