Class: LicenseFinder::License::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/license.rb

Direct Known Subclasses

Apache2, BSD, GPLv2, ISC, LGPL, MIT, NewBSD, Python, Ruby, SimplifiedBSD

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Base

Returns a new instance of Base.



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

def initialize(text)
  self.text = text
end

Class Attribute Details

.alternative_namesObject

Returns the value of attribute alternative_names.



31
32
33
# File 'lib/license_finder/license.rb', line 31

def alternative_names
  @alternative_names
end

.license_urlObject

Returns the value of attribute license_url.



31
32
33
# File 'lib/license_finder/license.rb', line 31

def license_url
  @license_url
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.demodulized_nameObject



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

def demodulized_name
  name.gsub(/^.*::/, '')
end

.inherited(descendant) ⇒ Object



33
34
35
# File 'lib/license_finder/license.rb', line 33

def inherited(descendant)
  License.all << descendant
end

.license_regexObject



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

def license_regex
  /#{Regexp.escape(license_text).gsub(/<[^<>]+>/, '(.*)')}/ if license_text
end

.license_textObject



57
58
59
60
61
62
63
64
# File 'lib/license_finder/license.rb', line 57

def license_text
  unless defined?(@license_text)
    template = ROOT_PATH.join("data", "licenses", "#{demodulized_name}.txt")

    @license_text = Text.new(template.read).to_s if template.exist?
  end
  @license_text
end

.namesObject



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

def names
  ([demodulized_name, pretty_name] + self.alternative_names).uniq
end

.pretty_nameObject



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

def pretty_name
  demodulized_name
end

.slugObject



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

def slug
  demodulized_name.downcase
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/license_finder/license.rb', line 81

def matches?
  !!(text =~ self.class.license_regex if self.class.license_regex)
end