Class: Kharon::Processors::BoxProcessor

Inherits:
Kharon::Processor show all
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.

Author:

Instance Attribute Summary

Attributes inherited from Kharon::Processor

#validator

Instance Method Summary (collapse)

Methods inherited from Kharon::Processor

#initialize

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.

Examples:

Validates a key so it has to be a box.

@validator.box(:a_box)

Parameters:

  • key (Object)

    the key about which verify the type.

  • options (Hash) (defaults to: {})

    a hash of options passed to this method (see documentation to know which options pass).



15
16
17
18
# File 'lib/kharon/processors/box_processor.rb', line 15

def process(key, options = {})
  before_all(key, options)
  match?(key, /^(?:[+-]?\d{1,3}(?:\.\d{1,7})?,?){4}$/) ? store(key, nil, options) : 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.

Parameters:

  • key (Object)

    the key associated with the value to store in the filtered datas.

  • process (Proc)

    a process (lambda) to execute on the initial value. Must contain strictly one argument.

  • options (Hash)

    the options applied to the initial value.



24
25
26
27
28
29
30
31
32
# File 'lib/kharon/processors/box_processor.rb', line 24

def store(key, process, options)
  if(options.has_key?(:at_least))
    box_contains?(key, validator.datas[key], options[:at_least])
  end
  if(options.has_key?(:at_most))
    box_contains?(key, options[:at_most], validator.datas[key])
  end
  super(key, ->(item){parse_box(key, validator.datas[key])}, options)
end