Test all languages can by found by name

This commit is contained in:
Joshua Peek
2011-05-25 09:27:20 -05:00
parent b047d67064
commit cbd69732f7
2 changed files with 26 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ require 'yaml'
module Linguist
class Language
@languages = []
@name_index = {}
@lexer_index = {}
@extension_index = {}
@@ -16,6 +17,8 @@ module Linguist
def self.create(attributes = {})
language = new(attributes)
@languages << language
# All Language names should be unique. Warn if there is a duplicate.
if @name_index.key?(language.name.downcase)
warn "Duplicate language name: #{language.name}"
@@ -51,6 +54,13 @@ module Linguist
language
end
# Public: Get all Languages
#
# Returns an Array of Languages
def self.all
@languages
end
# Public: Look up Language by its proper name.
#
# name - The case-insensitive String name of the Language
@@ -122,7 +132,7 @@ module Linguist
#
# Returns an Array of Lexers.
def self.popular
@popular ||= @name_index.values.select(&:popular?).sort_by { |lang| lang.name.downcase }
@popular ||= all.select(&:popular?).sort_by { |lang| lang.name.downcase }
end
# Public: A List of non-popular languages
@@ -134,7 +144,7 @@ module Linguist
#
# Returns an Array of Lexers.
def self.unpopular
@unpopular ||= @name_index.values.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
@unpopular ||= all.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
end
# Internal: Initialize a new Language