Class: SOCMaker::Parameter

Inherits:
Object
  • Object
show all
Includes:
ERR
Defined in:
lib/soc_maker/parameter.rb

Overview

Most of the fields are reserved for future implementations.

Direct Known Subclasses

SParameterEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#choiceObject

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

#defaultObject

default value



60
61
62
# File 'lib/soc_maker/parameter.rb', line 60

def default
  @default
end

#descriptionObject

description



75
76
77
# File 'lib/soc_maker/parameter.rb', line 75

def description
  @description
end

#editableObject

editable flag



72
73
74
# File 'lib/soc_maker/parameter.rb', line 72

def editable
  @editable
end

#maxObject

max value



66
67
68
# File 'lib/soc_maker/parameter.rb', line 66

def max
  @max
end

#minObject

min value



63
64
65
# File 'lib/soc_maker/parameter.rb', line 63

def min
  @min
end

#typeObject

type of the parameter



57
58
59
# File 'lib/soc_maker/parameter.rb', line 57

def type
  @type
end

#visibleObject

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