Class: CommentExtractor::Parser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extractor) ⇒ Parser

Returns a new instance of Parser.



10
11
12
# File 'lib/comment_extractor/parser.rb', line 10

def initialize(extractor)
  @extractor = extractor
end

Instance Attribute Details

#extractorObject

Returns the value of attribute extractor.



8
9
10
# File 'lib/comment_extractor/parser.rb', line 8

def extractor
  @extractor
end

Class Method Details

.for(file_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/comment_extractor/parser.rb', line 21

def for(file_path)
  if extractor = ExtractorManager.can_extract(file_path)
    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
end

Instance Method Details

#extract_commentsObject



14
15
16
17
18
# File 'lib/comment_extractor/parser.rb', line 14

def extract_comments
  @extractor.extract_comments
rescue NoMethodError
  raise TypeError, "#{@extractor} should be a instance of #{Extractor}"
end