2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class DSL
|
|
|
|
class License
|
|
|
|
# a generic category can always be given as a license, so
|
|
|
|
# category names should be given as both key and value
|
|
|
|
VALID_LICENSES = {
|
|
|
|
# license category
|
|
|
|
unknown: :unknown,
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
other: :other,
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
closed: :closed,
|
|
|
|
commercial: :closed,
|
|
|
|
gratis: :closed,
|
|
|
|
freemium: :closed,
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
oss: :oss,
|
|
|
|
affero: :oss,
|
|
|
|
apache: :oss,
|
|
|
|
arphic: :oss,
|
|
|
|
artistic: :oss,
|
|
|
|
bsd: :oss,
|
|
|
|
cc: :oss,
|
|
|
|
eclipse: :oss,
|
|
|
|
gpl: :oss,
|
|
|
|
isc: :oss,
|
|
|
|
lppl: :oss,
|
|
|
|
ncsa: :oss,
|
|
|
|
mit: :oss,
|
|
|
|
mpl: :oss,
|
|
|
|
ofl: :oss,
|
|
|
|
public_domain: :oss,
|
|
|
|
ubuntu_font: :oss,
|
|
|
|
x11: :oss,
|
|
|
|
}.freeze
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
DEFAULT_LICENSE = :unknown
|
|
|
|
DEFAULT_CATEGORY = VALID_LICENSES[DEFAULT_LICENSE]
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
attr_reader :value
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.check_constants
|
|
|
|
categories = Set.new(VALID_LICENSES.values)
|
|
|
|
categories.each do |cat|
|
|
|
|
next if VALID_LICENSES.key?(cat)
|
|
|
|
raise "license category is not a value: '#{@cat.inspect}'"
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.category(license)
|
|
|
|
VALID_LICENSES.fetch(license, DEFAULT_CATEGORY)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(arg)
|
|
|
|
@value = arg
|
|
|
|
@value = DEFAULT_LICENSE if @value.nil?
|
|
|
|
return if VALID_LICENSES.key?(@value)
|
|
|
|
raise "invalid license value: '#{@value.inspect}'"
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def category
|
|
|
|
self.class.category(@value)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
@value.inspect
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|