Class: Rouge::TextAnalyzer

Inherits:
String
  • Object
show all
Defined in:
lib/rouge/text_analyzer.rb

Instance Method Summary collapse

Instance Method Details

#doctypeObject



15
16
17
18
19
20
21
22
23
# File 'lib/rouge/text_analyzer.rb', line 15

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/rouge/text_analyzer.rb', line 25

def doctype?(type)
  type === doctype
end

#lexes_cleanly?(lexer) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/rouge/text_analyzer.rb', line 29

def lexes_cleanly?(lexer)
  lexer.lex(self) do |(tok, _)|
    return false if tok.name == 'Error'
  end

  true
end

#shebangObject



3
4
5
6
7
8
# File 'lib/rouge/text_analyzer.rb', line 3

def shebang
  return @shebang if instance_variable_defined? :@shebang

  self =~ /\A\s*#!(.*)$/
  @shebang = $1
end

#shebang?(match) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/rouge/text_analyzer.rb', line 10

def shebang?(match)
  match = /\b#{match}(\s|$)/
  match === shebang
end