Class: SourceNotes::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/source_notes.rb

Defined Under Namespace

Classes: Annotation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, options = {}) ⇒ Extractor

Returns a new instance of Extractor.



40
41
42
43
# File 'lib/source_notes.rb', line 40

def initialize(tag, options = {})
  @tag = tag
  @dirs = options[:dirs] || [Dir::pwd]
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



38
39
40
# File 'lib/source_notes.rb', line 38

def tag
  @tag
end

Class Method Details

.enumerate(tag, options = {}) ⇒ Object

Prints all annotations with tag tag under the current PWD Only filenames with extension .builder, .rb, .erb, .haml, .slim, .css, .scss, .js, and .coffee are taken into account. The options hash is passed to each annotation’s to_s.

This class method is the single entry point for the rake tasks.



33
34
35
36
# File 'lib/source_notes.rb', line 33

def self.enumerate(tag, options={})
  extractor = new(tag)
  extractor.display(options)
end

Instance Method Details

#display(options = {}) ⇒ Object

Prints the mapping from filenames to annotations in results ordered by filename. The options hash is passed to each annotation’s to_s.



47
48
49
50
51
52
53
54
55
56
# File 'lib/source_notes.rb', line 47

def display(options={})
  options[:indent] = find.map { |f, a| a.map(&:line) }.flatten.max.to_s.size
  find.keys.sort.each do |file|
    puts "#{file}:"
    find[file].each do |note|
      puts "  * #{note.to_s(options)}"
    end
    puts
  end
end