Class: Kharon::Processors::IntegerProcessor
- Inherits:
-
Kharon::Processor
- Object
- Kharon::Processor
- Kharon::Processors::IntegerProcessor
- Defined in:
- lib/kharon/processors/integer_processor.rb
Overview
Processor to validate integers. It has the :between, :min, and :max options 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 an integer or not.
-
- (Object) store(key, process, options = {})
Stores a numeric number after checking its limits if given.
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 an integer or not.
15 16 17 18 |
# File 'lib/kharon/processors/integer_processor.rb', line 15 def process(key, = {}) before_all(key, ) match?(key, /\A\d+\Z/) ? store(key, ->(item){item.to_i}, ) : raise_type_error(key, "Integer") end |
- (Object) store(key, process, options = {})
Stores a numeric number after checking its limits if given.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kharon/processors/integer_processor.rb', line 24 def store(key, process, = {}) if(.has_key?(:between)) check_min_value(key, [:between][0]) check_max_value(key, [:between][1]) else check_min_value(key, [:min]) if(.has_key?(:min)) check_max_value(key, [:max]) if(.has_key?(:max)) end super(key, process, ) end |