Class: Kharon::Processors::BoxProcessor
- Inherits:
-
Kharon::Processor
- Object
- Kharon::Processor
- Kharon::Processors::BoxProcessor
- Defined in:
- lib/kharon/processors/box_processor.rb
Overview
Processor to validate boxes. It has the :at_most and :at_least with the default ones.
Instance Attribute Summary
Attributes inherited from Kharon::Processor
Instance Method Summary (collapse)
-
- (Object) process(key, options = {})
Checks if the given key is a box (geofences) or not.
-
- (Object) store(key, process, options)
Tries to store the associated key in the filtered key, transforming it with the given process.
Methods inherited from Kharon::Processor
Constructor Details
This class inherits a constructor from Kharon::Processor
Instance Method Details
- (Object) process(key, options = {})
Checks if the given key is a box (geofences) or not. A box is composed of four numbers (positive or negative, decimal or not) separed by commas.
15 16 17 18 |
# File 'lib/kharon/processors/box_processor.rb', line 15 def process(key, = {}) before_all(key, ) match?(key, /^(?:[+-]?\d{1,3}(?:\.\d{1,7})?,?){4}$/) ? store(key, nil, ) : raise_type_error(key, "Box") end |
- (Object) store(key, process, options)
Tries to store the associated key in the filtered key, transforming it with the given process.
24 25 26 27 28 29 30 31 32 |
# File 'lib/kharon/processors/box_processor.rb', line 24 def store(key, process, ) if(.has_key?(:at_least)) box_contains?(key, validator.datas[key], [:at_least]) end if(.has_key?(:at_most)) box_contains?(key, [:at_most], validator.datas[key]) end super(key, ->(item){parse_box(key, validator.datas[key])}, ) end |