Class: Licensee::LicenseMeta

Inherits:
Struct
  • Object
show all
Includes:
HashHelper
Defined in:
lib/licensee/license_meta.rb

Constant Summary collapse

DEFAULTS =

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

{
  'featured' => false,
  'hidden'   => true
}.freeze
PREDICATE_FIELDS =
%i[featured hidden].freeze
HASH_METHODS =
members - %i[conditions permissions limitations spdx_id]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashHelper

#to_h

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions

Returns:

  • (Object)

    the current value of conditions



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def conditions
  @conditions
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def description
  @description
end

Returns the value of attribute featured

Returns:

  • (Object)

    the current value of featured



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def featured
  @featured
end

#hiddenObject

Returns the value of attribute hidden

Returns:

  • (Object)

    the current value of hidden



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def hidden
  @hidden
end

#howObject

Returns the value of attribute how

Returns:

  • (Object)

    the current value of how



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def how
  @how
end

#limitationsObject

Returns the value of attribute limitations

Returns:

  • (Object)

    the current value of limitations



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def limitations
  @limitations
end

#nicknameObject

Returns the value of attribute nickname

Returns:

  • (Object)

    the current value of nickname



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def nickname
  @nickname
end

#noteObject

Returns the value of attribute note

Returns:

  • (Object)

    the current value of note



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def note
  @note
end

#permissionsObject

Returns the value of attribute permissions

Returns:

  • (Object)

    the current value of permissions



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def permissions
  @permissions
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def source
  @source
end

#spdx_idObject

Returns the value of attribute spdx_id

Returns:

  • (Object)

    the current value of spdx_id



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def spdx_id
  @spdx_id
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def title
  @title
end

#usingObject

Returns the value of attribute using

Returns:

  • (Object)

    the current value of using



4
5
6
# File 'lib/licensee/license_meta.rb', line 4

def using
  @using
end

Class Method Details

.from_hash(hash) ⇒ Object

Create a new LicenseMeta from a hash

hash - the hash of key/value meta pairs

returns a LicenseMeta with defaults set



37
38
39
40
41
42
# 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) ⇒ Object

Create a new LicenseMeta from YAML

yaml - the raw YAML string

returns a LicenseMeta with defaults set



26
27
28
29
30
# 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_methodsObject

Array of symbolized helper methods to expose on the License class



45
46
47
# File 'lib/licensee/license_meta.rb', line 45

def helper_methods
  members - PREDICATE_FIELDS + PREDICATE_FIELDS.map { |f| :"#{f}?" }
end

Instance Method Details

#[](key) ⇒ Object

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



55
56
57
58
# File 'lib/licensee/license_meta.rb', line 55

def [](key)
  key = 'spdx_id' if key == 'spdx-id'
  super
end