Module: ActiveModel::AttributeFilters::Common::Squeeze
- Included in:
- ActiveModel::AttributeFilters::Common
- Defined in:
- lib/attribute-filters/common_filters/squeeze.rb
Overview
Squeezes white characters in attributes.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#squeeze_attributes
Squeezes white characters in attributes.
-
#squish_attributes
Squeezes white characters in attributes, removes leading and trailing spaces and newlines.
Methods included from FilteringRegistration
Instance Method Details
#squeeze_attributes
If a value of currently processed attribute is an array then any element of the array is changed. The same with hash (its values are changed).
This method returns an undefined value.
Squeezes white characters in attributes.
The attrubutes to be squeezed are taken from the attribute set called should_be_squeezed
. This method is safe to be used with multibyte strings (containing diacritics).
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/attribute-filters/common_filters/squeeze.rb', line 28 def squeeze_attributes filter_attrs_from_set(:should_be_squeezed) do |atr_val, atr_name, set_obj| other_str = set_obj.annotation(atr_name, :squeeze_other_str) if other_str.nil? AFHelpers.each_element(atr_val, String) do |v| v.mb_chars.squeeze.to_s end else AFHelpers.each_element(atr_val, String) do |v| v.mb_chars.squeeze(other_str).to_s end end end end |
#squish_attributes
If a value of currently processed attribute is an array then any element of the array is changed. The same with hash (its values are changed).
This method returns an undefined value.
Squeezes white characters in attributes, removes leading and trailing spaces and newlines.
The attrubutes to be squished are taken from the attribute set called should_be_squished
. This method is safe to be used with multibyte strings (containing diacritics).
69 70 71 72 73 74 75 |
# File 'lib/attribute-filters/common_filters/squeeze.rb', line 69 def squish_attributes filter_attrs_from_set(:should_be_squished) do |atr| AFHelpers.each_element(atr, String) do |v| v.mb_chars.squish.to_s end end end |