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.



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

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)
  @matcher     = settings.fetch(:matcher) { Matcher.from_template(Template.named(short_name)) }
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def all
  @all ||= Definitions.all
end

.find_by_name(name) ⇒ Object



18
19
20
21
# File 'lib/license_finder/license.rb', line 18

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

.find_by_text(text) ⇒ Object



23
24
25
# File 'lib/license_finder/license.rb', line 23

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

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  name.hash
end

#matches_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#matches_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#nameObject



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

def name
  pretty_name
end

#stripped_name(name) ⇒ Object



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

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