Class: Rembrandt::LanguageNormalizer

Inherits:
Object
  • Object
show all
Includes:
Engines::PygmentsKnownLanguages
Defined in:
lib/rembrandt/language_normalizer.rb

Instance Method Summary collapse

Methods included from Engines::PygmentsKnownLanguages

#known_languages

Instance Method Details

#known_language?(input) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rembrandt/language_normalizer.rb', line 7

def known_language?(input)
  known_languages.detect{|lang| lang == input}
end

#known_variant?(input) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rembrandt/language_normalizer.rb', line 11

def known_variant?(input)
  known_variants[input]
end

#known_variantsObject



15
16
17
18
19
# File 'lib/rembrandt/language_normalizer.rb', line 15

def known_variants
  {'ru'  => 'ruby',
   'm'   => 'objc',
   'yml' => 'yaml'}
end

#process(input) ⇒ Object



21
22
23
# File 'lib/rembrandt/language_normalizer.rb', line 21

def process(input)
  known_language?(input) || known_variant?(input) || raise_exception(input)
end

#raise_exception(input) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
# File 'lib/rembrandt/language_normalizer.rb', line 25

def raise_exception(input)
  raise ArgumentError.new("Unknown language specifier: #{input}")
end