Class: Jade::Decode::Desc::OptField

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

#innerObject (readonly)

Returns the value of attribute inner

Returns:

  • (Object)

    the current value of inner



122
123
124
# File 'lib/jade/decode.rb', line 122

def inner
  @inner
end

#keyObject (readonly)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



122
123
124
# File 'lib/jade/decode.rb', line 122

def key
  @key
end

Instance Method Details

#decode(value) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'lib/jade/decode.rb', line 125

def decode(value)
  h = coerce_hash(value)
  return type_err('Object', value) unless h

  raw = at_key(h, key.to_sym, key)
  return Jade::Maybe::Nothing[] if ABSENT.equal?(raw)

  decoded = inner.decode(raw)
  decoded?(decoded) ? Jade::Maybe::Just[decoded] : Failure.new(AtField[key.to_s, decoded.error])
end