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



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def conditions
  @conditions
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def description
  @description
end

Returns the value of attribute featured

Returns:

  • (Object)

    the current value of featured



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def featured
  @featured
end

#hiddenObject

Returns the value of attribute hidden

Returns:

  • (Object)

    the current value of hidden



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def hidden
  @hidden
end

#howObject

Returns the value of attribute how

Returns:

  • (Object)

    the current value of how



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def how
  @how
end

#limitationsObject

Returns the value of attribute limitations

Returns:

  • (Object)

    the current value of limitations



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def limitations
  @limitations
end

#nicknameObject

Returns the value of attribute nickname

Returns:

  • (Object)

    the current value of nickname



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def nickname
  @nickname
end

#noteObject

Returns the value of attribute note

Returns:

  • (Object)

    the current value of note



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def note
  @note
end

#permissionsObject

Returns the value of attribute permissions

Returns:

  • (Object)

    the current value of permissions



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def permissions
  @permissions
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def source
  @source
end

#spdx_idObject

Returns the value of attribute spdx_id

Returns:

  • (Object)

    the current value of spdx_id



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def spdx_id
  @spdx_id
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

def title
  @title
end

#usingObject

Returns the value of attribute using

Returns:

  • (Object)

    the current value of using



2
3
4
# File 'lib/licensee/license_meta.rb', line 2

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



35
36
37
38
39
40
# File 'lib/licensee/license_meta.rb', line 35

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



24
25
26
27
28
# File 'lib/licensee/license_meta.rb', line 24

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



43
44
45
# File 'lib/licensee/license_meta.rb', line 43

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

Instance Method Details

#[](key) ⇒ Object

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



53
54
55
56
# File 'lib/licensee/license_meta.rb', line 53

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