Class: Jade::Decode::Desc::Dct
- Inherits:
-
Data
- Object
- Data
- Jade::Decode::Desc::Dct
- Includes:
- Node
- Defined in:
- lib/jade/decode.rb
Instance Attribute Summary collapse
-
#k_inner ⇒ Object
readonly
Returns the value of attribute k_inner.
-
#v_inner ⇒ Object
readonly
Returns the value of attribute v_inner.
Instance Method Summary collapse
-
#decode(value) ⇒ Object
Two accepted wire shapes for Dict: a Hash (the natural Ruby form and what String-keyed JSON parses to) and an Array of [k, v] pairs (the form Encode.dict emits — survives non-String keys).
Methods included from Node
Instance Attribute Details
#k_inner ⇒ Object (readonly)
Returns the value of attribute k_inner
260 261 262 |
# File 'lib/jade/decode.rb', line 260 def k_inner @k_inner end |
#v_inner ⇒ Object (readonly)
Returns the value of attribute v_inner
260 261 262 |
# File 'lib/jade/decode.rb', line 260 def v_inner @v_inner end |
Instance Method Details
#decode(value) ⇒ Object
Two accepted wire shapes for Dict: a Hash (the natural Ruby form and what String-keyed JSON parses to) and an Array of [k, v] pairs (the form Encode.dict emits — survives non-String keys).
266 267 268 269 270 271 272 273 274 |
# File 'lib/jade/decode.rb', line 266 def decode(value) if (h = coerce_hash(value)) entries(h.each_pair.map { |k, v| [[k, v], k.to_s] }, :at_field) elsif ::Array === value entries(value.each_with_index.map { |pair, i| [pair, i] }, :at_index) else type_err('Object or Array', value) end end |