Sha256: f2e8f10888c088364d6578e281f4c28f14bfadac5dd9b721953df96e24b4db66

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

module CukeModeler

  # A class modeling a step's doc string.

  class DocString < Model

    include Parsed
    include Sourceable


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

    # The content of the doc string
    attr_accessor :content


    # Creates a new DocString object and, if *source_text* is provided, populates
    # the object.
    def initialize(source_text = nil)
      super(source_text)

      if source_text
        parsed_doc_string_data = parse_source(source_text)
        populate_docstring(self, parsed_doc_string_data)
      end
    end

    # Returns a string representation of this model. For a doc string model,
    # this will be Gherkin text that is equivalent to the doc string being modeled.
    def to_s
      text = "\"\"\"#{content_type_output_string}\n"
      text << content_output_string
      text << '"""'
    end


    private


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

      parsed_file = Parsing::parse_text(source_text, 'cuke_modeler_stand_alone_doc_string.feature')

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

    def content_type_output_string
      content_type ? " #{content_type}" : ''
    end

    def content_output_string
      (content.nil? || content.empty?) ? '' : content.gsub('"""', '\"\"\"') + "\n"
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cuke_modeler-1.0.4 lib/cuke_modeler/models/doc_string.rb
cuke_modeler-1.0.3 lib/cuke_modeler/models/doc_string.rb
cuke_modeler-1.0.2 lib/cuke_modeler/models/doc_string.rb
cuke_modeler-1.0.1 lib/cuke_modeler/models/doc_string.rb
cuke_modeler-1.0.0 lib/cuke_modeler/models/doc_string.rb