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

Direct Known Subclasses

AndLicense

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.



40
41
42
43
44
45
46
47
# File 'lib/license_finder/license.rb', line 40

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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



16
17
18
# File 'lib/license_finder/license.rb', line 16

def all
  @all ||= Definitions.all
end

.find_by_name(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/license_finder/license.rb', line 20

def find_by_name(name)
  name ||= 'unknown'
  license = all.detect { |l| l.matches_name? l.stripped_name(name) }

  if license
    license
  elsif name.include?(OrLicense.operator)
    OrLicense.new(name)
  elsif name.include?(AndLicense.operator)
    AndLicense.new(name)
  else
    Definitions.build_unrecognized(name)
  end
end

.find_by_text(text) ⇒ Object



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

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

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/license_finder/license.rb', line 71

def eql?(other)
  name == other.name
end

#hashObject



75
76
77
# File 'lib/license_finder/license.rb', line 75

def hash
  name.hash
end

#matches_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/license_finder/license.rb', line 63

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

#matches_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/license_finder/license.rb', line 67

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

#nameObject



51
52
53
# File 'lib/license_finder/license.rb', line 51

def name
  pretty_name
end

#standard_idObject



55
56
57
# File 'lib/license_finder/license.rb', line 55

def standard_id
  spdx_id
end

#stripped_name(name) ⇒ Object



59
60
61
# File 'lib/license_finder/license.rb', line 59

def stripped_name(name)
  name.sub(/^The /i, '')
end

#unrecognized_matcher?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/license_finder/license.rb', line 79

def unrecognized_matcher?
  matcher.is_a?(NoneMatcher)
end