Sha256: 189bb770c609d7ca2532a8d62a016d1c71d68c6218c113fcc2171da4b4647f26

Contents?: true

Size: 824 Bytes

Versions: 35

Compression:

Stored size: 824 Bytes

Contents

require 'gherkin/i18n'
require 'gherkin/native'

module Gherkin
  I18nLexerNotFound = Class.new(LoadError)
  LexingError = Class.new(StandardError)

  # The main entry point to lexing Gherkin source.
  class I18nLexer
    native_impl('gherkin')

    LANGUAGE_PATTERN = /language\s*:\s*(.*)/ #:nodoc:
    attr_reader :i18n_language

    def initialize(listener, force_ruby=false)
      @listener = listener
      @force_ruby = force_ruby
    end

    def scan(source)
      create_delegate(source).scan(source)
    end

  private

    def create_delegate(source)
      @i18n_language = lang(source)
      @i18n_language.lexer(@listener, @force_ruby)
    end

    def lang(source)
      line_one = source.split(/\n/)[0]
      match = LANGUAGE_PATTERN.match(line_one)
      I18n.get(match ? match[1] : 'en')
    end

  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
gherkin-2.1.1 lib/gherkin/i18n_lexer.rb
gherkin-2.1.1-i386-mswin32 lib/gherkin/i18n_lexer.rb
gherkin-2.1.1-i386-mingw32 lib/gherkin/i18n_lexer.rb
gherkin-2.1.1-universal-dotnet lib/gherkin/i18n_lexer.rb
gherkin-2.1.1-java lib/gherkin/i18n_lexer.rb
gherkin-2.1.0-i386-mswin32 lib/gherkin/i18n_lexer.rb
gherkin-2.1.0-i386-mingw32 lib/gherkin/i18n_lexer.rb
gherkin-2.1.0 lib/gherkin/i18n_lexer.rb
gherkin-2.1.0-universal-dotnet lib/gherkin/i18n_lexer.rb
gherkin-2.1.0-java lib/gherkin/i18n_lexer.rb
gherkin-1.0.30 lib/gherkin/i18n_lexer.rb
gherkin-1.0.30-i386-mswin32 lib/gherkin/i18n_lexer.rb
gherkin-1.0.30-i386-mingw32 lib/gherkin/i18n_lexer.rb
gherkin-1.0.30-universal-dotnet lib/gherkin/i18n_lexer.rb
gherkin-1.0.30-java lib/gherkin/i18n_lexer.rb