Module: ActiveModel::AttributeFilters::Common::Case

Included in:
ActiveModel::AttributeFilters::Common
Defined in:
lib/attribute-filters/common_filters/case.rb

Overview

This module contains attribute filters responsible for changing the case of letters.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from FilteringRegistration

#filtering_method

Instance Method Details

#capitalize_attributes

Note:

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.

Capitalizes attributes.

The attrubutes to be capitalized are taken from the attribute set called should_be_capitalized. This method is safe to be used with multibyte strings (containing diacritics).



120
121
122
123
124
125
126
# File 'lib/attribute-filters/common_filters/case.rb', line 120

def capitalize_attributes
  filter_attrs_from_set(:should_be_capitalized) do |atr|
    AFHelpers.each_element(atr, String) do |v|
      v.mb_chars.capitalize.to_s
    end
  end
end

#downcase_attributes

Note:

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.

Downcases attributes.

The attrubutes to be downcased are taken from the attribute set called should_be_downcased. This method is safe to be used with multibyte strings (containing diacritics).



30
31
32
33
34
35
36
# File 'lib/attribute-filters/common_filters/case.rb', line 30

def downcase_attributes
  filter_attrs_from_set(:should_be_downcased) do |atr|
    AFHelpers.each_element(atr, String) do |v|
      v.mb_chars.downcase.to_s
    end
  end
end

#fully_capitalize_attributes Also known as: titleize_with_squeezed_spaces

Note:

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.

Fully capitalizes attributes (capitalizes each word and squeezes spaces).

The attrubutes to be fully capitalized are taken from the attribute set called should_be_fully_capitalized and from set should_be_titleized. This method is safe to be used with multibyte strings (containing diacritics).



139
140
141
142
143
144
145
# File 'lib/attribute-filters/common_filters/case.rb', line 139

def fully_capitalize_attributes
  filter_attrs_from_set(:should_be_fully_capitalized) do |atr|
    AFHelpers.each_element(atr, String) do |v|
      v.mb_chars.split(' ').map { |n| n.capitalize }.join(' ')
    end
  end          
end

#titleize_attributes

Note:

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.

Titleizes attributes.

The attrubutes to be titleized are taken from the attribute set called should_be_titleized. This method is safe to be used with multibyte strings (containing diacritics).



90
91
92
93
94
95
96
# File 'lib/attribute-filters/common_filters/case.rb', line 90

def titleize_attributes
  filter_attrs_from_set(:should_be_titleized) do |atr|
    AFHelpers.each_element(atr, String) do |v|
      v.mb_chars.titleize.to_s
    end
  end
end

#upcase_attributes

Note:

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.

Upcases attributes.

The attrubutes to be upcased are taken from the attribute set called should_be_upcased. This method is safe to be used with multibyte strings (containing diacritics).



60
61
62
63
64
65
66
# File 'lib/attribute-filters/common_filters/case.rb', line 60

def upcase_attributes
  filter_attrs_from_set(:should_be_upcased) do |atr|
    AFHelpers.each_element(atr, String) do |v|
      v.mb_chars.upcase.to_s
    end
  end
end