Class: Issuesrc::TagExtractor

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

Instance Method Summary collapse

Constructor Details

#initialize(args, config) ⇒ TagExtractor

Returns a new instance of TagExtractor.


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/issuesrc/tag_extractor.rb', line 12

def initialize(args, config)
  @extractors = Issuesrc::Config.option_from_config(
    ['tags', 'extractors'], config)
  if @extractors.nil?
    @extractors = TAG_EXTRACTORS.clone
  end

  more = Issuesrc::Config.option_from_config(
    ['tags', 'additional_extractors'], config)
  if !more.nil?
    @extractors.merge! more
  end
end

Instance Method Details

#extract(source) ⇒ Issuesrc::Tag

Extracts a tag from a line of source code, if there is one.

It passes the line through one or more extractor functions. The first that returns non-nil will be returned.

Parameters:

  • source

    A string.

Returns:


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/issuesrc/tag_extractor.rb', line 33

def extract(source)
  @extractors.each do |extr|
    tag_data = try_extractor(extr, source)
    if !tag_data.nil?
      return Issuesrc::Tag.new(
        tag_data['type'],
        tag_data['issue_id'],
        tag_data['author'],
        tag_data['title'],
        nil, nil,
        tag_data['begin_pos'],
        tag_data['end_pos']
      )
    end
  end
  nil
end