Sha256: dc453c6cc07480a40692edeb5324121de3de03fb395b140ba96c6a99601061e1

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module CukeModeler

  # A class modeling a comment in a feature file.

  class Comment < Model

    include Parsing
    include Parsed
    include Sourceable


    # The text of the comment
    attr_accessor :text


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

      if source_text
        parsed_comment_data = parse_source(source_text)
        populate_comment(self, parsed_comment_data)
      end
    end

    # Returns a string representation of this model. For a comment model,
    # this will be Gherkin text that is equivalent to the comment being modeled.
    def to_s
      text || ''
    end


    private


    def parse_source(source_text)
      base_file_string = "\n#{dialect_feature_keyword}: Fake feature to parse"
      source_text = "# language: #{Parsing.dialect}\n" + source_text + base_file_string

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

      parsed_file['comments'].last
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cuke_modeler-3.3.0 lib/cuke_modeler/models/comment.rb
cuke_modeler-3.2.0 lib/cuke_modeler/models/comment.rb
cuke_modeler-3.1.0 lib/cuke_modeler/models/comment.rb
cuke_modeler-3.0.0 lib/cuke_modeler/models/comment.rb