Class: Label::SummaryExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/label/summary_extractor.rb

Overview

A class to extract the summary from the contents of a gemspec file

Constant Summary collapse

STRING_REGEXPS =
[
  /\"(?<content>[^"]*)\"/,
  /'(?<content>[^']*)'/,
  /%q\{(?<content>[^}]*)\}/i
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ SummaryExtractor

Returns a new instance of SummaryExtractor.



12
13
14
# File 'lib/label/summary_extractor.rb', line 12

def initialize content
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/label/summary_extractor.rb', line 4

def content
  @content
end

Instance Method Details

#extract_summaryObject



16
17
18
19
20
21
# File 'lib/label/summary_extractor.rb', line 16

def extract_summary
  STRING_REGEXPS.find do |regexp|
    md = content.match(/\w+\.summary\s+=\s+#{regexp}/)
    return md[:content] if md
  end
end