Class: SOCMaker::Parameter
- Inherits:
-
Object
- Object
- SOCMaker::Parameter
- Includes:
- ERR
- Defined in:
- lib/soc_maker/parameter.rb
Overview
Most of the fields are reserved for future implementations.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#choice ⇒ Object
choice: if type == ‘enum’, choice must be an array of choices.
-
#default ⇒ Object
default value.
-
#description ⇒ Object
description.
-
#editable ⇒ Object
editable flag.
-
#max ⇒ Object
max value.
-
#min ⇒ Object
min value.
-
#type ⇒ Object
type of the parameter.
-
#visible ⇒ Object
visibility.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Equality operator.
-
#encode_with(coder) ⇒ Object
Encoder method (to yaml).
-
#init_with(coder) ⇒ Object
Initialization method (from yaml).
-
#initialize(type, optional = {}) ⇒ Parameter
constructor
This constructor expects only the type as mandatory parameter, everything else can be passed as optional parameter.
Methods included from ERR
#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if
Constructor Details
#initialize(type, optional = {}) ⇒ Parameter
This constructor expects only the type as mandatory parameter, everything else can be passed as optional parameter.
84 85 86 |
# File 'lib/soc_maker/parameter.rb', line 84 def initialize( type, optional = {} ) init_with( { 'type' => type }.merge( optional ) ) end |
Instance Attribute Details
#choice ⇒ Object
choice: if type == ‘enum’, choice must be an array of choices
78 79 80 |
# File 'lib/soc_maker/parameter.rb', line 78 def choice @choice end |
#default ⇒ Object
default value
60 61 62 |
# File 'lib/soc_maker/parameter.rb', line 60 def default @default end |
#description ⇒ Object
description
75 76 77 |
# File 'lib/soc_maker/parameter.rb', line 75 def description @description end |
#editable ⇒ Object
editable flag
72 73 74 |
# File 'lib/soc_maker/parameter.rb', line 72 def editable @editable end |
#max ⇒ Object
max value
66 67 68 |
# File 'lib/soc_maker/parameter.rb', line 66 def max @max end |
#min ⇒ Object
min value
63 64 65 |
# File 'lib/soc_maker/parameter.rb', line 63 def min @min end |
#type ⇒ Object
type of the parameter
57 58 59 |
# File 'lib/soc_maker/parameter.rb', line 57 def type @type end |
#visible ⇒ Object
visibility
69 70 71 |
# File 'lib/soc_maker/parameter.rb', line 69 def visible @visible end |
Instance Method Details
#==(o) ⇒ Object
Equality operator
134 135 136 137 138 139 140 141 142 143 144 |
# 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 |
#encode_with(coder) ⇒ Object
Encoder method (to yaml)
coder-
An instance of the Psych::Coder to encode this class to a YAML file
93 94 95 96 97 98 99 |
# 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 |
#init_with(coder) ⇒ Object
Initialization method (from yaml)
coder-
An instance of the Psych::Coder to init this class from a YAML file
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# 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 |