Class: LicenseFinder::License

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/license.rb,
lib/license_finder/license/text.rb,
lib/license_finder/license/matcher.rb,
lib/license_finder/license/template.rb,
lib/license_finder/license/any_matcher.rb,
lib/license_finder/license/definitions.rb,
lib/license_finder/license/none_matcher.rb,
lib/license_finder/license/header_matcher.rb

Defined Under Namespace

Modules: Definitions, Text Classes: AnyMatcher, HeaderMatcher, Matcher, NoneMatcher, Template

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ License

Returns a new instance of License.



26
27
28
29
30
31
32
33
# File 'lib/license_finder/license.rb', line 26

def initialize(settings)
  @short_name  = settings.fetch(:short_name)
  @pretty_name = settings.fetch(:pretty_name, short_name)
  @other_names = settings.fetch(:other_names, [])
  @url         = settings.fetch(:url)
  @whitelisted = settings.fetch(:whitelisted, false)
  @matcher     = settings.fetch(:matcher) { Matcher.from_template(Template.named(short_name)) }
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



35
36
37
# File 'lib/license_finder/license.rb', line 35

def url
  @url
end

Class Method Details

.allObject



4
5
6
# File 'lib/license_finder/license.rb', line 4

def all
  @all ||= Definitions.all(LicenseFinder.config.whitelist)
end

.find_by_name(name) ⇒ Object



8
9
10
11
# File 'lib/license_finder/license.rb', line 8

def find_by_name(name)
  name ||= "other"
  all.detect { |l| l.matches_name? name } || Definitions.build_unrecognized(name, LicenseFinder.config.whitelist)
end

.find_by_text(text) ⇒ Object



13
14
15
# File 'lib/license_finder/license.rb', line 13

def find_by_text(text)
  all.detect { |l| l.matches_text? text }
end

Instance Method Details

#matches_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/license_finder/license.rb', line 41

def matches_name?(name)
  names.map(&:downcase).include? name.to_s.downcase
end

#matches_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/license_finder/license.rb', line 45

def matches_text?(text)
  matcher.matches_text?(text)
end

#nameObject



37
38
39
# File 'lib/license_finder/license.rb', line 37

def name
  pretty_name
end

#whitelistObject



53
54
55
# File 'lib/license_finder/license.rb', line 53

def whitelist
  copy(whitelisted: true)
end

#whitelisted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/license_finder/license.rb', line 49

def whitelisted?
  @whitelisted
end