Module: CommentExtractor::Extractors

Defined in:
lib/comment_extractor/extractors.rb

Class Method Summary collapse

Class Method Details

.can_extract(file_path) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/comment_extractor/extractors.rb', line 35

def can_extract(file_path)
  return if File.binary?(file_path)

  extractor = nil
  if shebang = File.shebang(file_path)
    extractor = find_by_shebang(shebang)
  end

  unless extractor
    extractor = find_by_filename(file_path)
  end

  if ::CommentExtractor.configuration.use_default_extractor
    extractor = default_extractor unless extractor
  end

  extractor
end

.default_extractorsObject


8
9
10
11
12
13
14
15
16
17
# File 'lib/comment_extractor/extractors.rb', line 8

def default_extractors
  %i[
    C Cc Class Clojure Coffee Cpp
    Cs Css Cxx D Erlang Fortran Go H Haml
    Haskell Hpp Html Java JavaScript Lisp
    Lua M Markdown Mm Perl Php Python
    Ruby Sass Scala Scss Shell Sqf
    Sql Sqs Tex Yaml
  ]
end

.regist_extractor(klass_or_symbol) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/comment_extractor/extractors.rb', line 19

def regist_extractor(klass_or_symbol)
  @extractor_definitions = nil
  extractor = klass_or_symbol.is_a?(Extractor) ? klass_or_symbol : nil
  extractors[:"#{klass_or_symbol}"] = extractor

  unless extractor
    filename = "#{klass_or_symbol}".gsub(/\W/, '').gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
    file_path = "comment_extractor/extractor/#{filename}"
    Extractor.autoload klass_or_symbol, file_path
  end
end