Class: Licensee::LicenseMeta
- Inherits:
-
Struct
- Object
- Struct
- Licensee::LicenseMeta
- 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
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#description ⇒ Object
Returns the value of attribute description.
-
#featured ⇒ Object
Returns the value of attribute featured.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#how ⇒ Object
Returns the value of attribute how.
-
#limitations ⇒ Object
Returns the value of attribute limitations.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
-
#note ⇒ Object
Returns the value of attribute note.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
-
#source ⇒ Object
Returns the value of attribute source.
-
#spdx_id ⇒ Object
Returns the value of attribute spdx_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#using ⇒ Object
Returns the value of attribute using.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Create a new LicenseMeta from a hash.
-
.from_yaml(yaml) ⇒ Object
Create a new LicenseMeta from YAML.
-
.helper_methods ⇒ Object
Array of symbolized helper methods to expose on the License class.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Backward compatibalize ‘#[“spdx-id”]` calls to avoid a breaking change.
Methods included from HashHelper
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def conditions @conditions end |
#description ⇒ Object
Returns the value of attribute description
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def description @description end |
#featured ⇒ Object
Returns the value of attribute featured
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def featured @featured end |
#hidden ⇒ Object
Returns the value of attribute hidden
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def hidden @hidden end |
#how ⇒ Object
Returns the value of attribute how
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def how @how end |
#limitations ⇒ Object
Returns the value of attribute limitations
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def limitations @limitations end |
#nickname ⇒ Object
Returns the value of attribute nickname
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def nickname @nickname end |
#note ⇒ Object
Returns the value of attribute note
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def note @note end |
#permissions ⇒ Object
Returns the value of attribute permissions
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def @permissions end |
#source ⇒ Object
Returns the value of attribute source
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def source @source end |
#spdx_id ⇒ Object
Returns the value of attribute spdx_id
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def spdx_id @spdx_id end |
#title ⇒ Object
Returns the value of attribute title
4 5 6 |
# File 'lib/licensee/license_meta.rb', line 4 def title @title end |
#using ⇒ Object
Returns the value of attribute 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_methods ⇒ Object
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 |