Module: ForbesFinder
- Defined in:
- lib/forbes-finder.rb,
lib/forbes-finder/errors.rb,
lib/forbes-finder/record.rb
Defined Under Namespace
Classes: EntryNotFound, Error, Record
Class Method Summary collapse
-
.cleanse_domain(domain) ⇒ Object
Clean the domain of things like ‘http(s)://’, ‘www’, ‘?foo=bar’, etc.
-
.lookup(domain) ⇒ Object
Look up a domain name to see if it’s the Forbes 2000 list.
-
.ranked?(domain) ⇒ Boolean
Returns true if a file is found matching the domain; false otherwise.
Class Method Details
.cleanse_domain(domain) ⇒ Object
Clean the domain of things like ‘http(s)://’, ‘www’, ‘?foo=bar’, etc.
Return the domain string.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/forbes-finder.rb', line 31 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 |
.lookup(domain) ⇒ Object
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.
13 14 15 16 17 |
# File 'lib/forbes-finder.rb', line 13 def lookup(domain) return if domain.nil? or domain.index('.') < 1 or !ranked?(domain) domain = cleanse_domain domain record = ForbesFinder::Record.new(domain) end |
.ranked?(domain) ⇒ Boolean
Returns true if a file is found matching the domain; false otherwise.
22 23 24 25 |
# File 'lib/forbes-finder.rb', line 22 def ranked?(domain) domain = cleanse_domain(domain) File.exists?(File.(__FILE__+"/../data/2012/#{domain}.toml")) end |