Sha256: 3a4ba7daf61e4c1a86a7f3cd1f65a4a918936619b14f47d92b4c9179ed7448ac

Contents?: true

Size: 1.11 KB

Versions: 3

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)

      return unless source_text

      parsed_comment_data = parse_source(source_text)
      populate_comment(self, parsed_comment_data)
    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

3 entries across 3 versions & 1 rubygems

Version Path
cuke_modeler-3.6.0 lib/cuke_modeler/models/comment.rb
cuke_modeler-3.5.0 lib/cuke_modeler/models/comment.rb
cuke_modeler-3.4.0 lib/cuke_modeler/models/comment.rb