Module: Rootage::Normalizer
- Defined in:
- lib/rootage/normalizer.rb
Overview
Normalizer
is a utility module that normalizes values into normalization
types. If values cannot normalize, this method raises
NormalizerValueError
. Normalization types are followings:
- boolean
- string
- integer
- positive_integer
- float
- date
And array is treated as special type, this type means the value should be included in the array.
Class Method Summary collapse
-
.normalize(type, val) ⇒ Object
Normalize the value as the normalization type.
-
.set(name) {|val| ... } ⇒ Object
Set normalization function.
Class Method Details
.normalize(type, val) ⇒ Object
Normalize the value as the normalization type.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rootage/normalizer.rb', line 25 def normalize(type, val) if type.nil? raise ArgumentError.new("Normalization type should not be nil.") end if respond_to?(type, true) send(type, val) else raise NormalizerTypeError.new(type) end end |
.set(name) {|val| ... } ⇒ Object
Set normalization function.
43 44 45 46 47 |
# File 'lib/rootage/normalizer.rb', line 43 def set(name, &block) singleton_class.instance_eval do define_method(name, &block) end end |