Sha256: 2e62ed78a32d5961982ad06f3383a964faf08e4c4e44883acc2ae90a178bcc32

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module SmartTodo
  module Parser
    # Represents a SmartTodo which includes the associated events
    # as well as the assignee.
    class TodoNode
      DEFAULT_RUBY_INDENTATION = 2

      attr_reader :metadata

      # @param todo [String] the actual Ruby comment
      def initialize(todo)
        @metadata = MetadataParser.parse(todo.gsub(/^#/, ""))
        @comments = []
        @start = todo.match(/^#(\s+)/)[1].size
      end

      # Return the associated comment for this TODO
      #
      # @return [String]
      def comment
        @comments.join
      end

      # @param comment [String]
      # @return [void]
      def <<(comment)
        @comments << comment.gsub(/^#(\s+)/, "")
      end

      # Check if the +comment+ is indented two spaces below the
      # TODO declaration. If yes the comment is considered to be part
      # of the TODO itself. Otherwise it's just a regular comment.
      #
      # @param comment [String]
      # @return [true, false]
      def indented_comment?(comment)
        comment.match(/^#(\s*)/)[1].size - @start == DEFAULT_RUBY_INDENTATION
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
smart_todo-1.6.0 lib/smart_todo/parser/todo_node.rb
smart_todo-1.5.0 lib/smart_todo/parser/todo_node.rb
smart_todo-1.4.3 lib/smart_todo/parser/todo_node.rb
smart_todo-1.3.1 lib/smart_todo/parser/todo_node.rb
smart_todo-1.3.0 lib/smart_todo/parser/todo_node.rb