Class: Jade::Decode::Desc::Dct

Inherits:
Data
  • Object
show all
Includes:
Node
Defined in:
lib/jade/decode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#decoded?

Instance Attribute Details

#k_innerObject (readonly)

Returns the value of attribute k_inner

Returns:

  • (Object)

    the current value of k_inner



260
261
262
# File 'lib/jade/decode.rb', line 260

def k_inner
  @k_inner
end

#v_innerObject (readonly)

Returns the value of attribute v_inner

Returns:

  • (Object)

    the current value of 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