class SOCMaker::Parameter
A small classes, used to group information and to verify, auto-correct and auto-complete this information: This class represents an instance parameter for a core with the following values:
-
type (mandatory)
-
default
-
min
-
max
-
visible
-
editable
-
description
Most of the fields are reserved for future implementations.
Attributes
choice: if type == 'enum', choice must be an array of choices
default value
description
editable flag
max value
min value
type of the parameter
visibility
Public Class Methods
This constructor expects only the type as mandatory parameter, everything else can be passed as optional parameter.
# File lib/soc_maker/parameter.rb, line 84 def initialize( type, optional = {} ) init_with( { 'type' => type }.merge( optional ) ) end
Public Instance Methods
Equality operator
# File lib/soc_maker/parameter.rb, line 134 def ==(o) o.class == self.class && o.type == self.type && o.default == self.default && o.min == self.min && o.max == self.max && o.visible == self.visible && o.editable == self.editable && o.description == self.description && o.choice == self.choice end
Encoder method (to yaml)
coder
-
An instance of the Psych::Coder to encode this class to a YAML file
# File lib/soc_maker/parameter.rb, line 93 def encode_with( coder ) init_error_if !coder.is_a?( Psych::Coder ), 'coder is not given as Psych::Coder' %w[ type default min max visible editable description ]. each { |v| coder[ v ] = instance_variable_get "@#{v}" } end
Initialization method (from yaml)
coder
-
An instance of the Psych::Coder to init this class from a YAML file
# File lib/soc_maker/parameter.rb, line 107 def init_with( coder ) init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 'coder is not given as Hash neither as Psych::Coder' init_error 'no parameter type specified', field: "type" if coder[ 'type' ] == nil @type = coder[ 'type' ] init_error "Parameter type is not defined with string", field: "parameter" if !@type.is_a?( String ) init_error "Parameter type string has zero length", field: "parameter" if @type.size == 0 @default = coder[ 'default' ] || 0 @min = coder[ 'min' ] || 0 @max = coder[ 'max' ] || 0 @visible = coder[ 'visible' ] || true @editable = coder[ 'editable' ] || false @description = coder[ 'description' ] || '' @choice = coder[ 'choice' ] || [] end