Module: Notes

Defined in:
lib/notes.rb,
lib/notes/scanner.rb,
lib/notes/version.rb

Defined Under Namespace

Classes: Note, Scanner

Constant Summary collapse

TAGS =

Default tags to grep in source code. They are TODO, FIXME, and XXX.

%w[TODO FIXME XXX]
VERSION =
"0.1.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scan(source, tags = nil, &block) ⇒ Enumerator

Scan a source string

Examples:

Notes.scan("...\nXXX fix this asap!") do |note|
  puts note.text
end

Parameters:

  • source (String)

    input source to scan

Returns:

  • (Enumerator)

    an enumerator on notes when no block is given



36
37
38
39
40
# File 'lib/notes.rb', line 36

def self.scan(source, tags = nil, &block)
  block.nil? and return enum_for(__method__, source, tags, &block)
  scanner = Scanner.new(tags, &block)
  scanner.scan(source)
end

.scan_file(file, tags = nil, &block) ⇒ Enumerator

Scan a file

Examples:

Notes.scan_file("src/foo.c") do |note|
  puts note.text
end

Notes.scan_file("bar.hs", ['@@@']) do |note|
  puts "File to fix: #{note.file}!"
end

Parameters:

  • filename (String)

    name of the file to scan

Returns:

  • (Enumerator)

    an enumerator on notes when no block is given



65
66
67
68
69
# File 'lib/notes.rb', line 65

def self.scan_file(file, tags = nil, &block)
  block.nil? and return enum_for(__method__, file, tags, &block)
  scanner = Scanner.new(tags, &block)
  scanner.scan_file(file)
end

Instance Method Details

#notes(tags = nil, &block) ⇒ Enumerator

Add a :notes method to an object

Examples:

file = File.new("foo.c")
file.extend Notes
file.notes do |note|
  puts note.text
end

Returns:

  • (Enumerator)

    an enumerator on notes when no block is given



89
90
91
92
93
94
# File 'lib/notes.rb', line 89

def notes(tags = nil, &block)
  block.nil? and return enum_for(__method__, tags, &block)
  scanner = Scanner.new(tags, &block)
  source = (self.respond_to? :read) ? self.read : self.to_s
  scanner.scan(source)
end