lib/license_finder/license.rb in license_finder-6.6.0 vs lib/license_finder/license.rb in license_finder-6.6.1

- old
+ new

@@ -17,10 +17,13 @@ @all ||= Definitions.all end def find_by_name(name) name ||= 'unknown' + return OrLicense.new(name) if name.include?(OrLicense.operator) + return AndLicense.new(name) if name.include?(AndLicense.operator) + all.detect { |l| l.matches_name? l.stripped_name(name) } || Definitions.build_unrecognized(name) end def find_by_text(text) all.detect { |l| l.matches_text? text } @@ -59,15 +62,48 @@ def hash name.hash end + def unrecognized_matcher? + matcher.is_a?(NoneMatcher) + end + private attr_reader :short_name, :pretty_name, :other_names attr_reader :matcher def names ([short_name, pretty_name] + other_names).uniq + end + end + class AndLicense < License + def self.operator + ' AND ' + end + + def initialize(name, operator = AndLicense.operator) + @short_name = name + @pretty_name = name + @url = nil + @matcher = NoneMatcher.new + # removes heading and trailing parentesis and splits + names = name[1..-2].split(operator) + @sub_licenses = names.map do |sub_name| + License.find_by_name(sub_name) + end + end + + attr_reader :sub_licenses + end + + class OrLicense < AndLicense + def self.operator + ' OR ' + end + + def initialize(name) + super(name, OrLicense.operator) end end end