Class: LcpRuby::Metadata::GroupDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Metadata::GroupDefinition
- Defined in:
- lib/lcp_ruby/metadata/group_definition.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Class Method Summary collapse
-
.from_hash(hash) ⇒ GroupDefinition
Factory method to build from a parsed YAML hash.
Instance Method Summary collapse
-
#initialize(name:, label: nil, description: nil, roles: []) ⇒ GroupDefinition
constructor
A new instance of GroupDefinition.
Constructor Details
#initialize(name:, label: nil, description: nil, roles: []) ⇒ GroupDefinition
Returns a new instance of GroupDefinition.
6 7 8 9 10 11 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 6 def initialize(name:, label: nil, description: nil, roles: []) @name = name.to_s @label = label || @name.titleize @description = description @roles = Array(roles).map(&:to_s) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 4 def description @description end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 4 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 4 def name @name end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
4 5 6 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 4 def roles @roles end |
Class Method Details
.from_hash(hash) ⇒ GroupDefinition
Factory method to build from a parsed YAML hash.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lcp_ruby/metadata/group_definition.rb', line 16 def self.from_hash(hash) hash = hash.transform_keys(&:to_s) name = hash["name"] if name.nil? || name.to_s.strip.empty? raise MetadataError, "Group definition must have a 'name' key" end new( name: name, label: hash["label"], description: hash["description"], roles: hash["roles"] || [] ) end |