class SmartTodo::Parser::CommentParser
This class is used to parse Ruby code and will stop each time a Ruby comment is encountered. It will detect if a TODO comment is a Smart Todo and will gather the comments associated to the TODO.
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/smart_todo/parser/comment_parser.rb, line 11 def initialize(*) super @node = nil end
Public Instance Methods
on_comment(comment, data)
click to toggle source
@param comment [String] the actual Ruby comment @param data [Array<TodoNode>] @return [Array<TodoNode>]
# File lib/smart_todo/parser/comment_parser.rb, line 19 def on_comment(comment, data) if todo_metadata?(comment) append_existing_node(data) @node = TodoNode.new(comment) elsif todo_comment?(comment) @node << comment else append_existing_node(data) @node = nil end data end
parse(init = [])
click to toggle source
@param init [Array] @return [Array<TodoNode>]
Calls superclass method
# File lib/smart_todo/parser/comment_parser.rb, line 35 def parse(init = []) super(init) init.tap { append_existing_node(init) } end
Private Instance Methods
append_existing_node(data)
click to toggle source
@param data [Array<TodoNode>] @return [Array<TodoNode>]
# File lib/smart_todo/parser/comment_parser.rb, line 66 def append_existing_node(data) data << @node if @node end
todo_comment?(comment)
click to toggle source
Check if the comment is associated with the Smart Todo @param comment [String] the actual Ruby comment @return [true, false]
@example When a comment is associated to a SmartTodo
TODO(on_date(...), to: '...') This is an associated comment
@example When a comment is not associated to a SmartTodo
TODO(on_date(...), to: '...') This is an associated comment (Note the indentation)
# File lib/smart_todo/parser/comment_parser.rb, line 60 def todo_comment?(comment) @node&.indented_comment?(comment) end
todo_metadata?(comment)
click to toggle source
@param comment [String] the actual Ruby comment @return [nil, Integer]
# File lib/smart_todo/parser/comment_parser.rb, line 45 def todo_metadata?(comment) /^#\sTODO\(/ =~ comment end