Class: Jade::Decode::Desc::Record
- Inherits:
-
Data
- Object
- Data
- Jade::Decode::Desc::Record
- Includes:
- Node
- Defined in:
- lib/jade/decode.rb
Instance Attribute Summary collapse
-
#ctor ⇒ Object
readonly
Returns the value of attribute ctor.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#decode(value) ⇒ Object
Spells out
at_keyanddecoded?rather than calling them: this runs once per field of every decoded row.
Methods included from Node
Instance Attribute Details
#ctor ⇒ Object (readonly)
Returns the value of attribute ctor
186 187 188 |
# File 'lib/jade/decode.rb', line 186 def ctor @ctor end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields
186 187 188 |
# File 'lib/jade/decode.rb', line 186 def fields @fields end |
Instance Method Details
#decode(value) ⇒ Object
Spells out at_key and decoded? rather than calling them:
this runs once per field of every decoded row.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/jade/decode.rb', line 191 def decode(value) h = coerce_hash(value) return type_err('Object', value) unless h size = fields.length args = ::Array.new(size) errors = nil i = 0 while i < size field = fields[i] key = field.key sym = field.sym raw = h[sym] raw = h[key] if raw.nil? if raw.nil? && !h.key?(sym) && !h.key?(key) (errors ||= []) << MissingField[key] else decoded = field.inner.decode(raw) Failure === decoded ? (errors ||= []) << AtField[key, decoded.error] : args[i] = decoded end i += 1 end errors ? Failure.new(wrap_errors(errors)) : ctor.new(*args) end |