Class: Rouge::TextAnalyzer
- Inherits:
-
String
- Object
- String
- Rouge::TextAnalyzer
- Defined in:
- lib/rouge/text_analyzer.rb
Instance Method Summary collapse
-
#doctype ⇒ Object
Return the contents of the doctype tag if present, nil otherwise.
-
#doctype?(type = //) ⇒ Boolean
Check if the doctype matches a given regexp or string.
-
#lexes_cleanly?(lexer) ⇒ Boolean
Return true if the result of lexing with the given lexer contains no error tokens.
-
#shebang ⇒ Object
Find a shebang.
-
#shebang?(match) ⇒ Boolean
Check if the given shebang is present.
Instance Method Details
#doctype ⇒ Object
Return the contents of the doctype tag if present, nil otherwise.
23 24 25 26 27 28 29 30 31 |
# File 'lib/rouge/text_analyzer.rb', line 23 def doctype return @doctype if instance_variable_defined? :@doctype self =~ %r(\A\s* (?:<\?.*?\?>\s*)? # possible <?xml...?> tag <!DOCTYPE\s+(.+?)> )xm @doctype = $1 end |
#doctype?(type = //) ⇒ Boolean
Check if the doctype matches a given regexp or string
34 35 36 |
# File 'lib/rouge/text_analyzer.rb', line 34 def doctype?(type=//) type === doctype end |
#lexes_cleanly?(lexer) ⇒ Boolean
Return true if the result of lexing with the given lexer contains no error tokens.
40 41 42 43 44 45 46 |
# File 'lib/rouge/text_analyzer.rb', line 40 def lexes_cleanly?(lexer) lexer.lex(self) do |(tok, _)| return false if tok.name == 'Error' end true end |
#shebang ⇒ Object
Find a shebang. Returns nil if no shebang is present.
6 7 8 9 10 11 |
# File 'lib/rouge/text_analyzer.rb', line 6 def shebang return @shebang if instance_variable_defined? :@shebang self =~ /\A\s*#!(.*)$/ @shebang = $1 end |
#shebang?(match) ⇒ Boolean
Check if the given shebang is present.
This normalizes things so that ‘text.shebang?(’bash’)‘ will detect `#!/bash`, ’#!/bin/bash’, ‘#!/usr/bin/env bash’, and ‘#!/bin/bash -x’
17 18 19 20 |
# File 'lib/rouge/text_analyzer.rb', line 17 def shebang?(match) match = /\b#{match}(\s|$)/ match === shebang end |