strip HRs before looking for title and copyright

This commit is contained in:
Ben Balter 2017-03-28 09:47:55 -04:00
parent b126b63e4c
commit ff900d31a4
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
4 changed files with 11 additions and 8 deletions

View File

@ -5,6 +5,7 @@ module Licensee
module ContentHelper
DIGEST = Digest::SHA1
END_OF_TERMS_REGEX = /^\s*end of terms and conditions\s*$/i
HR_REGEX = /^\s*[=-]{4,}/
ALT_TITLE_REGEX = {
'bsd-2-clause' => /bsd 2-clause( \"simplified\")? license/i,
'bsd-3-clause' => /bsd 3-clause( \"new\" or \"revised\")? license/i,
@ -55,6 +56,7 @@ module Licensee
def content_without_title_and_version
@content_without_title_and_version ||= begin
string = content.strip
string = strip_hrs(string)
string = strip_title(string) while string =~ title_regex
strip_version(string).strip
end
@ -68,7 +70,6 @@ module Licensee
while string =~ Matchers::Copyright::REGEX
string = strip_copyright(string)
end
string = strip_hrs(string)
string, _partition, _instructions = string.partition(END_OF_TERMS_REGEX)
strip_whitespace(string)
end
@ -101,7 +102,7 @@ module Licensee
# Strip HRs from MPL
def strip_hrs(string)
string.gsub(/[=-]{4,}/, '')
string.gsub HR_REGEX, ''
end
def strip_whitespace(string)

View File

@ -1,4 +1,5 @@
# encoding: UTF-8
module Licensee
module Matchers
class Copyright

View File

@ -10,13 +10,14 @@ end
RSpec.describe Licensee::ContentHelper do
let(:content) do
<<-EOS.freeze
The MIT License
The MIT License
===============
Copyright 2016 Ben Balter
Copyright 2016 Ben Balter
The made
up license.
-----------
The made
up license.
-----------
EOS
end
subject { ContentHelperTestHelper.new(content) }

View File

@ -35,7 +35,7 @@ RSpec.describe Licensee::License do
end
it "doesn't include hidden licenses" do
expect(licenses).to all satisfy { |license| !license.hidden? }
expect(licenses).to all(satisfy { |license| !license.hidden? })
end
it 'includes featured licenses' do