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
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def conditions @conditions end |
#description ⇒ Object
Returns the value of attribute description
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def description @description end |
#featured ⇒ Object
Returns the value of attribute featured
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def featured @featured end |
#hidden ⇒ Object
Returns the value of attribute hidden
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def hidden @hidden end |
#how ⇒ Object
Returns the value of attribute how
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def how @how end |
#limitations ⇒ Object
Returns the value of attribute limitations
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def limitations @limitations end |
#nickname ⇒ Object
Returns the value of attribute nickname
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def nickname @nickname end |
#note ⇒ Object
Returns the value of attribute note
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def note @note end |
#permissions ⇒ Object
Returns the value of attribute permissions
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def @permissions end |
#source ⇒ Object
Returns the value of attribute source
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def source @source end |
#spdx_id ⇒ Object
Returns the value of attribute spdx_id
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def spdx_id @spdx_id end |
#title ⇒ Object
Returns the value of attribute title
2 3 4 |
# File 'lib/licensee/license_meta.rb', line 2 def title @title end |
#using ⇒ Object
Returns the value of attribute 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_methods ⇒ Object
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 |