Sha256: 32dc921b5294d3b2e80581e65733124a2293fb3d51e13cd65c70b60af87f905b

Contents?: true

Size: 1.18 KB

Versions: 31

Compression:

Stored size: 1.18 KB

Contents

# -*- coding: utf-8 -*- #

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

31 entries across 29 versions & 4 rubygems

Version Path
rougegal-2.1.2 lib/rouge/text_analyzer.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.1.1/lib/rouge/text_analyzer.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.0.7/lib/rouge/text_analyzer.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rouge-2.0.7/lib/rouge/text_analyzer.rb
rouge-2.1.1 lib/rouge/text_analyzer.rb
rouge-2.1.0 lib/rouge/text_analyzer.rb
tdiary-5.0.4 vendor/bundle/gems/rouge-2.0.7/lib/rouge/text_analyzer.rb
rouge-2.0.7 lib/rouge/text_analyzer.rb
rouge-2.0.6 lib/rouge/text_analyzer.rb
rouge-2.0.5 lib/rouge/text_analyzer.rb
rouge-2.0.3 lib/rouge/text_analyzer.rb
rouge-2.0.2 lib/rouge/text_analyzer.rb
rouge-2.0.1 lib/rouge/text_analyzer.rb
rouge-2.0.0 lib/rouge/text_analyzer.rb
rouge-1.11.1 lib/rouge/text_analyzer.rb
rouge-1.11.0 lib/rouge/text_analyzer.rb
rouge-1.10.1 lib/rouge/text_analyzer.rb
rouge-1.10.0 lib/rouge/text_analyzer.rb
gitlab-rouge-1.9.2 lib/rouge/text_analyzer.rb
rouge-1.9.1 lib/rouge/text_analyzer.rb