Sha256: 2edb11f4d3eecf3294ef2bcdc6d0ccc122a6fddd1c4f057fc03efb7c1791332d
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require 'json' require 'net/http' require 'uri' json = Net::HTTP.get(URI('https://spdx.org/licenses/licenses.json')) licenses = JSON.parse(json)['licenses'].map do |licenseObject| licenseObject['licenseId'] end open 'lib/rubygems/util/licenses.rb', 'w' do |io| io.write <<-RUBY # frozen_string_literal: true require 'rubygems/text' class Gem::Licenses extend Gem::Text NONSTANDARD = 'Nonstandard'.freeze # Software Package Data Exchange (SPDX) standard open-source software # license identifiers IDENTIFIERS = %w( #{licenses.sort.join "\n "} ).freeze REGEXP = %r{ \\A ( \#{Regexp.union(IDENTIFIERS)} \\+? (\\s WITH \\s .+)? | \#{NONSTANDARD} ) \\Z }ox.freeze def self.match?(license) !REGEXP.match(license).nil? end def self.suggestions(license) by_distance = IDENTIFIERS.group_by do |identifier| levenshtein_distance(identifier, license) end lowest = by_distance.keys.min return unless lowest < license.size by_distance[lowest] end end RUBY end
Version data entries
6 entries across 6 versions & 1 rubygems