class LicenseFinder::License::Base
def alternative_names
def alternative_names @alternative_names ||= [] end
def demodulized_name
def demodulized_name name.gsub(/^.*::/, '') end
def inherited(descendant)
def inherited(descendant) LicenseFinder::License.all << descendant end
def initialize(text)
def initialize(text) self.text = text end
def license_regex
def license_regex /#{Regexp.escape(license_text).gsub(/<[^<>]+>/, '(.*)')}/ if license_text end
def license_text
def license_text unless defined?(@license_text) template = File.join(LicenseFinder::ROOT_PATH, "data", "licenses", "#{demodulized_name}.txt").to_s @license_text = Text.new(File.read(template)).to_s if File.exists?(template) end @license_text end
def matches?
def matches? !!(text =~ self.class.license_regex if self.class.license_regex) end
def names
def names [demodulized_name] + self.alternative_names end
def pretty_name
def pretty_name demodulized_name end
def slug
def slug demodulized_name.downcase end
def text=(text)
def text=(text) @text = Text.new(text).to_s end