Sha256: eee55c7d8e02f082d76b03394e435039f2efbe6e3ec6f9518f5b8ead7fa68695

Contents?: true

Size: 586 Bytes

Versions: 1

Compression:

Stored size: 586 Bytes

Contents

require "spdx/version"
require "spdx-licenses"
require "text"

module Spdx
  def self.find(name)
    SpdxLicenses[name] || closest(name)
  end

  def self.closest(name)
    name.gsub!(/software|license/i, '')
    match = names.sort_by do |key|
      Text::Levenshtein.distance(name, key)
    end.first
    SpdxLicenses[match] || find_by_name(match)
  end

  def self.find_by_name(name)
    match = SpdxLicenses.data.find{|k,v| v['name'] == name }
    SpdxLicenses[match[0]] if match
  end

  def self.names
    SpdxLicenses.data.keys + SpdxLicenses.data.map{|k,v| v['name'] }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spdx-1.0.0 lib/spdx.rb