Sha256: d00f1b9c983d001d99e396127dfec7bfcbfedfe6f74a54701112157ee369b4bc

Contents?: true

Size: 1.16 KB

Versions: 41

Compression:

Stored size: 1.16 KB

Contents

module Rouge
  class TextAnalyzer < String
    # Find a shebang.  Returns nil if no shebang is present.
    def shebang
      return @shebang if instance_variable_defined? :@shebang

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

    # 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'
    def shebang?(match)
      match = /\b#{match}(\s|$)/
      match === shebang
    end

    # Return the contents of the doctype tag if present, nil otherwise.
    def doctype
      return @doctype if instance_variable_defined? :@doctype

      self =~ %r(\A\s*
        (?:<\?.*?\?>\s*)? # possible <?xml...?> tag
        <!DOCTYPE\s+(.+?)>
      )xm
      @doctype = $1
    end

    # Check if the doctype matches a given regexp or string
    def doctype?(type=//)
      type === doctype
    end

    # Return true if the result of lexing with the given lexer contains no
    # error tokens.
    def lexes_cleanly?(lexer)
      lexer.lex(self) do |(tok, _)|
        return false if tok.name == 'Error'
      end

      true
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
rouge-1.5.0 lib/rouge/text_analyzer.rb
rouge-1.4.0 lib/rouge/text_analyzer.rb
rouge-1.3.4 lib/rouge/text_analyzer.rb
rouge-1.3.3 lib/rouge/text_analyzer.rb
rouge-1.3.2 lib/rouge/text_analyzer.rb
rouge-1.3.1 lib/rouge/text_analyzer.rb
rouge-1.3.0 lib/rouge/text_analyzer.rb
rouge-1.2.0 lib/rouge/text_analyzer.rb
rouge-1.1.0 lib/rouge/text_analyzer.rb
rouge-0.5.4 lib/rouge/text_analyzer.rb
rouge-0.5.3 lib/rouge/text_analyzer.rb
rouge-0.5.2 lib/rouge/text_analyzer.rb
rouge-0.5.1 lib/rouge/text_analyzer.rb
rouge-0.5.0 lib/rouge/text_analyzer.rb
rouge-0.4.0 lib/rouge/text_analyzer.rb
rouge-0.3.10 lib/rouge/text_analyzer.rb
rouge-0.3.9 lib/rouge/text_analyzer.rb
rouge-0.3.8 lib/rouge/text_analyzer.rb
rouge-0.3.7 lib/rouge/text_analyzer.rb
rouge-0.3.6 lib/rouge/text_analyzer.rb