Class: Jade::Decode::Desc::Idx

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

#indexObject (readonly)

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



151
152
153
# File 'lib/jade/decode.rb', line 151

def index
  @index
end

#innerObject (readonly)

Returns the value of attribute inner

Returns:

  • (Object)

    the current value of inner



151
152
153
# File 'lib/jade/decode.rb', line 151

def inner
  @inner
end

Instance Method Details

#decode(value) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/jade/decode.rb', line 154

def decode(value)
  return type_err('Array', value) unless ::Array === value
  return Failure.new(MissingField["[#{index}]"]) if index >= value.length

  decoded = inner.decode(value[index])
  decoded?(decoded) ? decoded : Failure.new(AtIndex[index, decoded.error])
end