Class: FortuneFinder

Inherits:
Object
  • Object
show all
Includes:
NaughtyOrNice
Defined in:
lib/fortune-finder.rb,
lib/fortune-finder/record.rb

Defined Under Namespace

Classes: Record

Constant Summary collapse

YEAR =
2015

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



23
24
25
# File 'lib/fortune-finder.rb', line 23

def all
  @all ||= Dir["#{domains_path}/*.toml"].map { |d| lookup File.basename(d, ".toml") }.sort_by { |d| d.rank }
end

.domains_pathObject



15
16
17
# File 'lib/fortune-finder.rb', line 15

def domains_path
  @domains_path ||= File.expand_path "./data/#{YEAR}", File.dirname(__FILE__)
end

.lookup(domain) ⇒ Object



19
20
21
# File 'lib/fortune-finder.rb', line 19

def lookup(domain)
  FortuneFinder.new(domain).lookup
end

.ranked?Object



13
# File 'lib/fortune-finder.rb', line 13

alias_method :ranked?, :valid?

Instance Method Details

#fortune100?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/fortune-finder.rb', line 38

def fortune100?
  ranked? && record.rank <= 100
end

#fortune500?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fortune-finder.rb', line 42

def fortune500?
  ranked? && record.rank <= 500
end

#fortune50?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/fortune-finder.rb', line 34

def fortune50?
  ranked? && record.rank <= 50
end

#recordObject Also known as: lookup

Look up a domain name to see if it’s the Fortune 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.



51
52
53
54
55
56
# File 'lib/fortune-finder.rb', line 51

def record
  @record ||= begin
    record = FortuneFinder::Record.new(domain)
    record if record.exists?
  end
end

#valid?Boolean Also known as: ranked?, fortune1000?

Returns:

  • (Boolean)


28
29
30
# File 'lib/fortune-finder.rb', line 28

def valid?
  !!record
end