Sha256: 1efe78c41070e6cc9020cc619900a1036b714c8724c415199e4ad3dfcb98cbee

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

require 'stringio'
require 'gherkin/formatter/json_formatter'
require 'gherkin'
require 'json'
require 'multi_json'

module CukeModeler

  # A module providing source text parsing functionality.

  module Parsing

    class << self

      # Parses the Cucumber feature given in *source_text* and returns an array
      # containing the hash representation of its logical structure.
      def parse_text(source_text)
        raise(ArgumentError, "Cannot parse #{source_text.class} objects. Strings only.") unless source_text.is_a?(String)

        io = StringIO.new
        formatter = Gherkin::Formatter::JSONFormatter.new(io)
        parser = Gherkin::Parser::Parser.new(formatter)
        parser.parse(source_text, 'fake_file.txt', 0)
        formatter.done

        MultiJson.load(io.string)
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuke_modeler-0.0.2 lib/cuke_modeler/parsing.rb
cuke_modeler-0.0.1 lib/cuke_modeler/parsing.rb