Class: Rouge::Guessers::Filename
- Inherits:
-
Rouge::Guesser
- Object
- Rouge::Guesser
- Rouge::Guessers::Filename
- Defined in:
- lib/rouge/guessers/filename.rb
Instance Attribute Summary collapse
-
#fname ⇒ Object
readonly
Returns the value of attribute fname.
Instance Method Summary collapse
-
#filter(lexers) ⇒ Object
returns a list of lexers that match the given filename with equal specificity (i.e. number of wildcards in the pattern).
-
#initialize(filename) ⇒ Filename
constructor
A new instance of Filename.
Methods inherited from Rouge::Guesser
Constructor Details
#initialize(filename) ⇒ Filename
Returns a new instance of Filename.
7 8 9 |
# File 'lib/rouge/guessers/filename.rb', line 7 def initialize(filename) @filename = filename end |
Instance Attribute Details
#fname ⇒ Object (readonly)
Returns the value of attribute fname.
6 7 8 |
# File 'lib/rouge/guessers/filename.rb', line 6 def fname @fname end |
Instance Method Details
#filter(lexers) ⇒ Object
returns a list of lexers that match the given filename with equal specificity (i.e. number of wildcards in the pattern). This helps disambiguate between, e.g. the Nginx lexer, which matches ‘nginx.conf`, and the Conf lexer, which matches `*.conf`. In this case, nginx will win because the pattern has no wildcards, while `*.conf` has one.
17 18 19 20 21 22 23 24 |
# File 'lib/rouge/guessers/filename.rb', line 17 def filter(lexers) mapping = {} lexers.each do |lexer| mapping[lexer.name] = lexer.filenames || [] end GlobMapping.new(mapping, @filename).filter(lexers) end |