Sha256: e418a5c66f89e4fc311c3b1db154a2598cf75dd81d66c99b61aed6f150e0f647

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module CucumberAnalytics

  # A class modeling the Doc String of a Step.

  class DocString

    # The parent object that contains *self*
    attr_accessor :parent_element

    # The content type associated with the doc string
    attr_accessor :content_type

    # The contents of the doc string
    attr_accessor :contents


    # Creates a new DocString object and, if *source* is provided, populates
    # the object.
    def initialize(source = nil)
      @contents = []

      parsed_doc_string = process_source(source)

      build_doc_string(parsed_doc_string) if parsed_doc_string
    end


    private


    def process_source(source)
      case
        when source.is_a?(String)
          parse_doc_string(source)
        else
          source
      end
    end

    def parse_doc_string(source_text)
      base_file_string = "Feature:\nScenario:\n* step\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing::parse_text(source_text)

      parsed_file.first['elements'].first['steps'].first['doc_string']
    end

    def build_doc_string(doc_string)
      @content_type = doc_string['content_type'] == "" ? nil : doc_string['content_type']
      @contents = doc_string['value'].split($/)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber_analytics-1.1.1 lib/cucumber_analytics/doc_string.rb
cucumber_analytics-1.0.0 lib/cucumber_analytics/doc_string.rb