Module: NFLTeams

Defined in:
lib/nfl_teams.rb,
lib/nfl_teams/data.rb

Defined Under Namespace

Modules: Data

Class Method Summary collapse

Class Method Details

.abbreviation(location_or_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nfl_teams.rb', line 13

def self.abbreviation(location_or_name)
  team_by_name = NFLTeams::Data::TEAMS.find { |t| t[:name] == location_or_name }

  return team_by_name[:abbreviation] if team_by_name

  teams_by_location = NFLTeams::Data::TEAMS.find_all { |t| t[:location] == location_or_name }
  abbrv_location = teams_by_location.map { |t| t[:abbreviation] }

  return abbrv_location.first if abbrv_location.size == 1
  return abbrv_location if abbrv_location.size > 1

  nil
end

.allObject



5
6
7
# File 'lib/nfl_teams.rb', line 5

def self.all
  NFLTeams::Data::TEAMS
end

.full_namesObject



9
10
11
# File 'lib/nfl_teams.rb', line 9

def self.full_names
  NFLTeams::Data::TEAMS.map { |t| "#{t[:location]} #{t[:name]}" }
end

.search(string) ⇒ Object



27
28
29
30
# File 'lib/nfl_teams.rb', line 27

def self.search(string)
  fz = FuzzyMatch.new(NFLTeams.all, :read => Proc.new { |a| "#{a[:location]} #{a[:name]} - #{a[:abbreviation]}" })
  fz.find(string)
end