Class: ML_ruby::ML_compound
- Inherits:
-
Object
- Object
- ML_ruby::ML_compound
show all
- Defined in:
- lib/ml-ruby/ml_data_types.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ML_compound.
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/ml-ruby/ml_data_types.rb', line 138
def initialize data
self.class.attributes.each do |attr,type|
set_compound_attribute( attr, data[attr], type )
end
if self.class.conditions
self.class.conditions.each do |test,|
key=data[test].payload
[key].each do |attr,type|
set_compound_attribute( attr, data[attr], type )
end if [key]
end
end
end
|
Class Method Details
.attributes ⇒ Object
132
133
134
|
# File 'lib/ml-ruby/ml_data_types.rb', line 132
def self.attributes
@attributes
end
|
.conditions ⇒ Object
135
136
137
|
# File 'lib/ml-ruby/ml_data_types.rb', line 135
def self.conditions
@conditions
end
|
.decode(data) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/ml-ruby/ml_data_types.rb', line 171
def self.decode data
attributes={}
self.attributes.each do |attr,type|
attributes[attr]= type.decode data
data= data[attributes[attr].size..-1]
end
if conditions
conditions.each do |test,|
key= attributes[test].payload
[key].each do |attr,type|
attributes[attr]= type.decode data
data= data[attributes[attr].size..-1]
end if [key]
end
end
self.new attributes
end
|
Instance Method Details
#encode ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/ml-ruby/ml_data_types.rb', line 154
def encode
result=""
self.class.attributes.each do |attr,type|
result<<( send( attr ).encode )
end
if self.class.conditions
self.class.conditions.each do |test,|
key= send( test ).payload
[key].each do |attr,type|
result<<( send( attr ).encode )
end if [key]
end
end
result
end
|
#size ⇒ Object
151
152
153
|
# File 'lib/ml-ruby/ml_data_types.rb', line 151
def size
self.class.attributes.inject( 0 ) { |sum,attr| sum+send( attr[0] ).size }
end
|