class Licensee::LicenseMeta

Constants

DEFAULTS

These should be in sync with choosealicense.com’s collection defaults

HASH_METHODS
PREDICATE_FIELDS

Public Class Methods

from_hash(hash) click to toggle source

Create a new LicenseMeta from a hash

hash - the hash of key/value meta pairs

returns a LicenseMeta with defaults set

# File lib/licensee/license_meta.rb, line 37
def from_hash(hash)
  hash = DEFAULTS.merge(hash)
  hash['spdx_id'] = hash.delete('spdx-id')
  ordered_array = hash.values_at(*members.map(&:to_s))
  new(*ordered_array)
end
from_yaml(yaml) click to toggle source

Create a new LicenseMeta from YAML

yaml - the raw YAML string

returns a LicenseMeta with defaults set

# File lib/licensee/license_meta.rb, line 26
def from_yaml(yaml)
  return from_hash({}) if yaml.nil? || yaml.to_s.empty?

  from_hash YAML.safe_load(yaml)
end
helper_methods() click to toggle source

Array of symbolized helper methods to expose on the License class

# File lib/licensee/license_meta.rb, line 45
def helper_methods
  members - PREDICATE_FIELDS + PREDICATE_FIELDS.map { |f| "#{f}?".to_sym }
end

Public Instance Methods

[](key) click to toggle source

Backward compatibalize ‘#[“spdx-id”]` calls to avoid a breaking change

Calls superclass method
# File lib/licensee/license_meta.rb, line 55
def [](key)
  key = 'spdx_id' if key == 'spdx-id'
  super(key)
end
source() click to toggle source
# File lib/licensee/license_meta.rb, line 60
def source
  "https://spdx.org/licenses/#{spdx_id}.html" if spdx_id
end