Class: Janeway::Interpreters::IndexSelectorDeleter
- Inherits:
-
IndexSelectorInterpreter
- Object
- Base
- IndexSelectorInterpreter
- Janeway::Interpreters::IndexSelectorDeleter
- Defined in:
- lib/janeway/interpreters/index_selector_deleter.rb
Overview
Interprets an index selector, and deletes the matched value.
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#interpret(input, _parent, _root, _path) ⇒ Object
Interpret selector on the given input.
Methods inherited from Base
#as_json, #initialize, #selector, #to_s, #type
Constructor Details
This class inherits a constructor from Janeway::Interpreters::Base
Instance Method Details
#interpret(input, _parent, _root, _path) ⇒ Object
Interpret selector on the given input.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/janeway/interpreters/index_selector_deleter.rb', line 14 def interpret(input, _parent, _root, _path) return [] unless input.is_a?(Array) index = selector.value result = input.fetch(index) # raises IndexError if no such index input.delete_at(index) # returns nil if deleted value is nil, or if no value was deleted [result] rescue IndexError [] end |