Class: CommentExtractor::Parser
- Inherits:
-
Object
- Object
- CommentExtractor::Parser
- Defined in:
- lib/comment_extractor/parser.rb
Instance Attribute Summary collapse
-
#extractor ⇒ Object
Returns the value of attribute extractor.
Class Method Summary collapse
Instance Method Summary collapse
- #extract_comments ⇒ Object
-
#initialize(extractor) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(extractor) ⇒ Parser
Returns a new instance of Parser.
8 9 10 |
# File 'lib/comment_extractor/parser.rb', line 8 def initialize(extractor) @extractor = extractor end |
Instance Attribute Details
#extractor ⇒ Object
Returns the value of attribute extractor.
6 7 8 |
# File 'lib/comment_extractor/parser.rb', line 6 def extractor @extractor end |
Class Method Details
.for(file_path) ⇒ Object
18 19 20 21 22 |
# File 'lib/comment_extractor/parser.rb', line 18 def self.for(file_path) if extractor = Extractors.can_extract(file_path) self.initialize_with_extractor(file_path, extractor) end end |
.initialize_with_extractor(file_path, extractor) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/comment_extractor/parser.rb', line 24 def self.initialize_with_extractor(file_path, extractor) content = File.open(file_path, 'r') { |f| f.read_content } # Initialize parser code_objects = CodeObjects.new(file: file_path) instance_of_extractor = extractor.new(content, code_objects) new(instance_of_extractor) end |
Instance Method Details
#extract_comments ⇒ Object
12 13 14 15 16 |
# File 'lib/comment_extractor/parser.rb', line 12 def extract_comments @extractor.extract_comments rescue NoMethodError raise TypeError, "#{@extractor} should be a instance of #{Extractor}" end |