Sha256: d0a7ebed00206cdc9b806364d6772897f6673039c1ca1eee957914d4295c532e

Contents?: true

Size: 592 Bytes

Versions: 4

Compression:

Stored size: 592 Bytes

Contents

require 'gherkin/lexer'
require 'gherkin/i18n'

module Gherkin
  # The main entry point to lexing Gherkin source.
  class I18nLexer
    LANGUAGE_PATTERN = /language\s*:\s*(.*)/ #:nodoc:

    attr_reader :language

    def initialize(parser)
      @parser = parser
    end

    def scan(source)
      @language = lang(source) 
      delegate = Lexer[@language.key].new(@parser)
      delegate.scan(source)
    end

    private

    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

4 entries across 4 versions & 1 rubygems

Version Path
gherkin-1.0.2-i386-mswin32 lib/gherkin/i18n_lexer.rb
gherkin-1.0.2-i386-mingw32 lib/gherkin/i18n_lexer.rb
gherkin-1.0.2-java lib/gherkin/i18n_lexer.rb
gherkin-1.0.2 lib/gherkin/i18n_lexer.rb