Class: AnnotationExtractor
- Inherits:
-
Object
- Object
- AnnotationExtractor
- Defined in:
- lib/notes.rb
Defined Under Namespace
Classes: Annotation
Constant Summary collapse
- VERSION =
"0.0.3"
- TAGS =
Default tags list
["TODO", "FIXME", "OPTIMIZE"]
Class Attribute Summary collapse
-
.tags ⇒ Object
Returns the value of attribute tags.
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
The list of all notes.
Instance Method Summary collapse
-
#get(tag) ⇒ Object
Get annotation with tag ‘tag’ from the list.
-
#initialize(source = Dir.pwd) ⇒ AnnotationExtractor
constructor
Instanciate a new extractor for the given target files.
-
#write(file) ⇒ Object
Write all annotations to the file ‘file’.
Constructor Details
#initialize(source = Dir.pwd) ⇒ AnnotationExtractor
Instanciate a new extractor for the given target files.
45 46 47 48 49 50 |
# File 'lib/notes.rb', line 45 def initialize(source = Dir.pwd) @source = [].push(source).flatten @list = Array.new extract end |
Class Attribute Details
.tags ⇒ Object
Returns the value of attribute tags.
35 36 37 |
# File 'lib/notes.rb', line 35 def @tags end |
Instance Attribute Details
#list ⇒ Object (readonly)
The list of all notes.
42 43 44 |
# File 'lib/notes.rb', line 42 def list @list end |
Instance Method Details
#get(tag) ⇒ Object
Get annotation with tag ‘tag’ from the list.
53 54 55 |
# File 'lib/notes.rb', line 53 def get(tag) @list.find_all { |a| a.tag == tag } end |
#write(file) ⇒ Object
Write all annotations to the file ‘file’.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/notes.rb', line 58 def write(file) longest_tag = @list.max { |a, b| a.tag.size <=> b.tag.size }.tag.size File.open(file, 'w') do |f| @list.each do |a| f.write(sprintf(" * [%-#{longest_tag}s] %s (%s): %s\n", a.tag, a.file, a.line, a.text)) end end end |