normatron 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. data/.yardopts +2 -0
  2. data/lib/normatron/filters.rb +42 -24
  3. data/lib/normatron/filters/ascii_filter.rb +18 -12
  4. data/lib/normatron/filters/blank_filter.rb +19 -15
  5. data/lib/normatron/filters/camelize_filter.rb +39 -34
  6. data/lib/normatron/filters/capitalize_filter.rb +19 -13
  7. data/lib/normatron/filters/chomp_filter.rb +27 -21
  8. data/lib/normatron/filters/dasherize_filter.rb +16 -10
  9. data/lib/normatron/filters/downcase_filter.rb +19 -13
  10. data/lib/normatron/filters/dump_filter.rb +20 -14
  11. data/lib/normatron/filters/keep_filter.rb +101 -84
  12. data/lib/normatron/filters/remove_filter.rb +26 -21
  13. data/lib/normatron/filters/squeeze_filter.rb +24 -16
  14. data/lib/normatron/filters/squish_filter.rb +20 -13
  15. data/lib/normatron/filters/strip_filter.rb +25 -17
  16. data/lib/normatron/filters/swapcase_filter.rb +19 -13
  17. data/lib/normatron/filters/titleize_filter.rb +19 -13
  18. data/lib/normatron/filters/underscore_filter.rb +28 -22
  19. data/lib/normatron/filters/upcase_filter.rb +19 -13
  20. data/lib/normatron/version.rb +1 -1
  21. data/spec/normatron/configuration_spec.rb +0 -1
  22. data/spec/normatron/extensions/active_record_spec.rb +1 -0
  23. data/spec/normatron/filters/ascii_filter_spec.rb +15 -9
  24. data/spec/normatron/filters/blank_filter_spec.rb +10 -11
  25. data/spec/normatron/filters/camelize_filter_spec.rb +94 -33
  26. data/spec/normatron/filters/capitalize_filter_spec.rb +8 -7
  27. data/spec/normatron/filters/squeeze_filter_spec.rb +2 -2
  28. data/spec/spec_helper.rb +6 -1
  29. data/spec/support/matchers/evaluate_matcher.rb +75 -0
  30. metadata +5 -2
@@ -0,0 +1,2 @@
1
+ --protected
2
+ --markup textile
@@ -4,34 +4,52 @@ end
4
4
 
5
5
  module Normatron
6
6
 
7
+ ##
7
8
  # Top-Level namespace of all built-in Normatron filters.
8
9
  #
9
10
  # All filters share some characteristics:
10
- # * They have the <code>Filter</code> suffix in the name.
11
- # * Has a class method called <code>evaluate</code>, which runs what the filter claims to do.
12
- # * The first argument of the method <code>evaluate</code> always will be the variable to be filtered.
13
- # * They returns a different object from the input variable, i.e., even if object value remains unchanged, the <code>object_id</code> will be different.
14
- # * They treat unicode characters(<code>/\p{Ll}\p{Lu}/u</code>) instead of only ASCII characters(<code>/[a-zA-Z]/</code>).
15
- #
16
- # table{font-family: monospace; font-size: 90%}.
17
- # |_. CLASS |_. SYMBOL |_. SHORT DESCRIPTION |
18
- # |"AsciiFilter":./Filters/AsciiFilter |:ascii |Converts Unicode(and accented ASCII) characters to their plain-text ASCII equivalents.|
19
- # |"BlankFilter":./Filters/BlankFilter |:blank |Returns nil for a blank string or the string itself otherwise. |
20
- # |"CamelizeFilter":./Filters/CamelizeFilter |:camelize |Convert string to UpperCamelCase or lowerCamelCase. |
21
- # |"CapitalizeFilter":./Filters/CapitalizeFilter|:capitalize|Makes only the first character as capital letter. |
22
- # |"ChompFilter":./Filters/ChompFilter |:chomp |Remove the given record separator from the end of the string. |
23
- # |"DasherizeFilter":./Filters/DasherizeFilter |:dasherize |Replaces all underscores with dashes. |
24
- # |"DowncaseFilter":./Filters/DowncaseFilter |:downcase |Lowercase all characters. |
25
- # |"DumpFilter":./Filters/DumpFilter |:dump |Creates a literal string representation. |
26
- # |"KeepFilter":./Filters/KeepFilter |:keep |Remove the characters that doesn't match the given properties. |
27
- # |"RemoveFilter":./Filters/RemoveFilter |:remove |Remove the characters that match the given properties. |
28
- # |"SqueezeFilter":./Filters/SqueezeFilter |:squeeze |Remove multiple occurences of the same character. |
29
- # |"SquishFilter":./Filters/SquishFilter |:squish |Strips the input, remove line-breaks and multiple spaces. |
30
- # |"SwapcaseFilter":./Filters/SwapcaseFilter |:swapcase |Replaces uppercased characters by lowercased and vice versa. |
31
- # |"TitleizeFilter":./Filters/TitleizeFilter |:titleize |Capitalizes the first character of each word. |
32
- # |"UnderscoreFilter":./Filters/UnderscoreFilter|:underscore|Makes an underscored lowercase form from the expression in the string. |
33
- # |"UpcaseFilter":./Filters/UpcaseFilter |:upcase |Uppercase all characters. |
11
+ #
12
+ # * They have the _Filter_ suffix in the name.
13
+ # * Has a class method called @evaluate@, which runs what the filter claims to do.
14
+ # * The first argument of the @evaluate@ method always will be the variable to be filtered.
15
+ # * When filtraton is done succesfully, the @object_id@ of filtered value and input value are different.
16
+ # * They treat unicode characters(@/[\p{Ll}\p{Lu}]/u@) instead of only ASCII characters(@/[a-zA-Z]/@).
17
+ #
18
+ # |_<. Class |_<. Symbol |_<. Short Description |
19
+ # | "@AsciiFilter@":./Filters/AsciiFilter | @:ascii@ | Converts Unicode(and accented ASCII) characters to their plain-text ASCII equivalents. |
20
+ # | "@BlankFilter@":./Filters/BlankFilter | @:blank@ | Returns nil for a blank string or the string itself otherwise. |
21
+ # | "@CamelizeFilter@":./Filters/CamelizeFilter | @:camelize@ | Convert string to UpperCamelCase or lowerCamelCase. |
22
+ # | "@CapitalizeFilter@":./Filters/CapitalizeFilter | @:capitalize@ | Makes only the first character as capital letter. |
23
+ # | "@ChompFilter@":./Filters/ChompFilter | @:chomp@ | Remove the given record separator from the end of the string. |
24
+ # | "@DasherizeFilter@":./Filters/DasherizeFilter | @:dasherize@ | Replaces all underscores with dashes. |
25
+ # | "@DowncaseFilter@":./Filters/DowncaseFilter | @:downcase@ | Lowercase all characters. |
26
+ # | "@DumpFilter@":./Filters/DumpFilter | @:dump@ | Creates a literal string representation. |
27
+ # | "@KeepFilter@":./Filters/KeepFilter | @:keep@ | Remove the characters that doesn't match the given properties. |
28
+ # | "@RemoveFilter@":./Filters/RemoveFilter | @:remove@ | Remove the characters that match the given properties. |
29
+ # | "@SqueezeFilter@":./Filters/SqueezeFilter | @:squeeze@ | Remove multiple occurences of the same character. |
30
+ # | "@SquishFilter@":./Filters/SquishFilter | @:squish@ | Strips the input, remove line-breaks and multiple spaces. |
31
+ # | "@SwapcaseFilter@":./Filters/SwapcaseFilter | @:swapcase@ | Replaces uppercased characters by lowercased and vice versa. |
32
+ # | "@TitleizeFilter@":./Filters/TitleizeFilter | @:titleize@ | Capitalizes the first character of each word. |
33
+ # | "@UnderscoreFilter@":./Filters/UnderscoreFilter | @:underscore@ | Makes an underscored lowercase form from the expression in the string. |
34
+ # | "@UpcaseFilter@":./Filters/UpcaseFilter | @:upcase@ | Uppercase all characters. |
34
35
  module Filters
35
36
  end
36
37
  end
37
38
 
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
@@ -2,23 +2,29 @@ require 'stringex/unidecoder'
2
2
 
3
3
  module Normatron
4
4
  module Filters
5
+
6
+ ##
7
+ # Converts Unicode(and accented ASCII) characters to their plain-text ASCII equivalents.
8
+ #
9
+ # @example Out of box
10
+ # AsciiFilter.evaluate("EVOLUÇÃO") #=> "EVOLUCAO"
11
+ # AsciiFilter.evaluate("⠋⠗⠁⠝⠉⠑") #=> "france"
12
+ #
13
+ # @example Using as model normalizer
14
+ # normalize :attribute_a, :with => :ascii
15
+ # normalize :attribute_b, :with => [:custom_filter, :ascii]
16
+ #
17
+ # @see http://rubydoc.info/gems/stringex/Stringex/Unidecoder Stringex::Unidecoder
5
18
  module AsciiFilter
6
19
 
7
20
  ##
8
- # Converts Unicode(and accented ASCII) characters to their plain-text ASCII equivalents.
9
- #
10
- # @example
11
- # AsciiFilter.evaluate("EVOLUÇÃO") #=> "EVOLUCAO"
12
- # AsciiFilter.evaluate("⠋⠗⠁⠝⠉⠑") #=> "france"
21
+ # Performs input conversion according to filter requirements.
13
22
  #
14
- # @example Using as ActiveRecord::Base normalizer
15
- # normalize :attribute_a, :with => :ascii
16
- # normalize :attribute_b, :with => [:custom_filter, :ascii]
23
+ # This method returns the object itself when the first argument is not a String.
17
24
  #
18
- # @param [String] input A character sequence
19
- # @return [String] The transliterated character sequence or the object itself
20
- # @see http://rubydoc.info/gems/stringex/Stringex/Unidecoder Stringex::Unidecoder
21
- def self.evaluate(input, *args)
25
+ # @param input [String] The String to be filtered
26
+ # @return [String] A new transliterated String
27
+ def self.evaluate(input)
22
28
  input.kind_of?(String) ? Stringex::Unidecoder.decode(input) : input
23
29
  end
24
30
  end
@@ -1,26 +1,30 @@
1
- require 'normatron/filters/helpers'
2
-
3
1
  module Normatron
4
2
  module Filters
3
+
4
+ ##
5
+ # Returns nil for a blank string or the string itself otherwise.
6
+ #
7
+ # @example Out of box
8
+ # BlankFilter.evaluate("") #=> nil
9
+ # BlankFilter.evaluate(" ") #=> nil
10
+ # BlankFilter.evaluate(" \n ") #=> nil
11
+ # BlankFilter.evaluate("1") #=> "1"
12
+ # BlankFilter.evaluate("It's blank?") #=> "It's blank?"
13
+ #
14
+ # @example Using as model normalizer
15
+ # normalize :attribute_a, :with => :blank
16
+ # normalize :attribute_b, :with => [:custom_filter, :blank]
17
+ #
18
+ # @see http://api.rubyonrails.org/classes/String.html#method-i-blank-3F String#blank?
5
19
  module BlankFilter
6
20
 
7
21
  ##
8
- # Returns nil for a blank string or the string itself otherwise.
9
- #
10
- # @example
11
- # BlankFilter.evaluate("") #=> nil
12
- # BlankFilter.evaluate(" ") #=> nil
13
- # BlankFilter.evaluate(" \n ") #=> nil
14
- # BlankFilter.evaluate("1") #=> "1"
15
- # BlankFilter.evaluate("It's blank?") #=> "It's blank?"
22
+ # Performs input conversion according to filter requirements.
16
23
  #
17
- # @example Using as ActiveRecord::Base normalizer
18
- # normalize :attribute_a, :with => :blank
19
- # normalize :attribute_b, :with => [:custom_filter, :blank]
24
+ # This method returns the object itself when the first argument is not a String.
20
25
  #
21
- # @param input [String] A character sequence
26
+ # @param input [String] The String to be filtered
22
27
  # @return [String, nil] The object itself or nil
23
- # @see http://api.rubyonrails.org/classes/String.html#method-i-blank-3F String#blank?
24
28
  def self.evaluate(input)
25
29
  input.kind_of?(String) && input.blank? ? nil : input
26
30
  end
@@ -2,48 +2,53 @@ require 'normatron/filters/helpers'
2
2
 
3
3
  module Normatron
4
4
  module Filters
5
+
6
+ ##
7
+ # Converts strings to UpperCamelCase by default and to lowerCamelCase if the @:lower@ argument is given.
8
+ #
9
+ # It will also convert '/' to '::' which is useful for converting paths to namespaces.
10
+ #
11
+ # As a rule of thumb you can think of camelize as the inverse of underscore, though there are cases where that does
12
+ # not hold:
13
+ #
14
+ # pre. "SSLError".underscore.camelize # => "SslError"
15
+ #
16
+ # This filter has a similar behavior to
17
+ # "ActiveSupport::Inflector#camelize (ActiveSupport camelize)":http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize,
18
+ # but it affects UTF-8 characters too.
19
+ #
20
+ # @example Out of box
21
+ # CamelizeFilter.evaluate("active_record/errors") #=> "ActiveRecord::Errors"
22
+ # CamelizeFilter.evaluate("active_record/errors", :upper) #=> "ActiveRecord::Errors"
23
+ # CamelizeFilter.evaluate("active_record/errors", :lower) #=> "activeRecord::Errors"
24
+ #
25
+ # @example Using as model normalizer
26
+ # normalize :attribute_a, :with => :camelize
27
+ # normalize :attribute_b, :with => [:custom_filter, :camelize]
28
+ # normalize :attribute_c, :with => [[:camelize, :lower]]
29
+ # normalize :attribute_d, :with => [{:camelize => :lower}]
30
+ # normalize :attribute_e, :with => [:custom_filter, [:camelize, :lower]]
31
+ # normalize :attribute_f, :with => [:custom_filter, {:camelize => :lower}]
32
+ #
33
+ # @see http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize ActiveSupport::Inflector#camelize
34
+ # @see UnderscoreFilter Normatron::Filters::UnderscoreFilter
5
35
  module CamelizeFilter
6
36
  extend Helpers
7
37
 
8
38
  ##
9
- # Converts strings to UpperCamelCase by default and to lowerCamelCase if the <tt>:lower</tt> argument is given.
10
- # <tt>camelize</tt> will also convert '/' to '::' which is useful for converting paths to namespaces.
11
- # As a rule of thumb you can think of camelize as the inverse of underscore, though there are cases where that does not hold:
12
- # "SSLError".underscore.camelize # => "SslError"
13
- # This filter has a similar behavior to
14
- # ActiveSupport::Inflector#camelize[http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize], but with following differences:
15
- # * Uses UTF-8 charset
16
- # * Affects accented characters
17
- #
18
- # @example
19
- # CamelizeFilter.evaluate("active_record/errors") #=> "ActiveRecord::Errors"
20
- # CamelizeFilter.evaluate("active_record/errors", :upper) #=> "ActiveRecord::Errors"
21
- # CamelizeFilter.evaluate("active_record/errors", :lower) #=> "activeRecord::Errors"
39
+ # Performs input conversion according to filter requirements.
22
40
  #
23
- # @example Using as ActiveRecord::Base normalizer
24
- # normalize :attribute_a, :with => :camelize
25
- # normalize :attribute_b, :with => [:custom_filter, :camelize]
26
- # normalize :attribute_c, :with => [[:camelize, :lower]]
27
- # normalize :attribute_d, :with => [{:camelize => :lower}]
28
- # normalize :attribute_e, :with => [:custom_filter, [:camelize, :lower]]
29
- # normalize :attribute_f, :with => [:custom_filter, {:camelize => :lower}]
41
+ # This method returns the object itself when the first argument is not a String.
30
42
  #
31
- # @param [String] input A character sequence
32
- # @param [Symbol] first_letter_case <tt>:lower</tt> for lowerCamelCase or <tt>:upper</tt> for UpperCamelCase
33
- # @return [String] The camelized character sequence or the object itself
34
- # @see http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize ActiveSupport::Inflector#camelize
35
- # @see UnderscoreFilter Normatron::Filters::UnderscoreFilter
36
- # @todo Performance tests
37
- # @todo Exception class
38
- def self.evaluate(input, first_letter_case = :upper)
43
+ # @param input [String] The String to be filtered
44
+ # @param camel [Symbol] @:lower@ for lowerCamelCase or @:upper@ for UpperCamelCase
45
+ # @return [String] A new camelized String
46
+ def self.evaluate(input, camel = :upper)
39
47
  return input unless input.kind_of?(String)
40
48
 
41
- if first_letter_case == :upper
42
- string = input.sub(/^[\p{L}\d]*/u) { acronyms[$&] || mb_send(:capitalize, $&) }
43
- else first_letter_case == :lower
44
- string = input.sub(/^(?:#{acronym_regex}(?=\b|[\p{L}_])|\p{Word}*_)/u) { mb_send(:downcase, $&) }
45
- end
46
- string.gsub!(/(?:_|(\/))([\p{L}\d]*)/iu) { "#{$1}#{acronyms[$2] || mb_send(:capitalize, $2)}" }.gsub!('/', '::')
49
+ string = mb_send(:downcase, input)
50
+ string.sub!(/^[^_|\/]+/) { camel == :upper ? acronyms[$&] || mb_send(:capitalize, $&) : $& }
51
+ string.gsub(/(?:(\/)|_)([^\/|_]+)/) { "#{$1}#{acronyms[$2] || mb_send(:capitalize, $2)}" }.gsub("/", "::")
47
52
  end
48
53
  end
49
54
  end
@@ -2,25 +2,31 @@ require 'normatron/filters/helpers'
2
2
 
3
3
  module Normatron
4
4
  module Filters
5
+
6
+ ##
7
+ # Makes the first character uppercase and all remaining characters lowercase.
8
+ #
9
+ # @example Out of box
10
+ # CapitalizeFilter.evaluate("KEEP IT SIMPLE") #=> "Keep it simple"
11
+ # CapitalizeFilter.evaluate("keep it simple") #=> "Keep it simple"
12
+ # CapitalizeFilter.evaluate(" KEEP IT SIMPLE") #=> " keep it simple"
13
+ #
14
+ # @example Using as model normalizer
15
+ # normalize :attribute_a, :with => :capitalize
16
+ # normalize :attribute_b, :with => [:custom_filter, :capitalize]
17
+ #
18
+ # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-capitalize String#capitalize
19
+ # @see TitleizeFilter Normatron::Filters::TitleizeFilter
5
20
  module CapitalizeFilter
6
21
  extend Helpers
7
22
 
8
23
  ##
9
- # Makes the first character uppercase after lowercase all other characters.
10
- #
11
- # @example
12
- # CapitalizeFilter.evaluate("KEEP IT SIMPLE") #=> "Keep it simple"
13
- # CapitalizeFilter.evaluate("keep it simple") #=> "Keep it simple"
14
- # CapitalizeFilter.evaluate(" KEEP IT SIMPLE") #=> " keep it simple"
24
+ # Performs input conversion according to filter requirements.
15
25
  #
16
- # @example Using as ActiveRecord::Base normalizer
17
- # normalize :attribute_a, :with => :capitalize
18
- # normalize :attribute_b, :with => [:custom_filter, :capitalize]
26
+ # This method returns the object itself when the first argument is not a String.
19
27
  #
20
- # @param [String] input A character sequence
21
- # @return [String] The capitalized character sequence or the object itself
22
- # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-capitalize String#capitalize
23
- # @see TitleizeFilter Normatron::Filters::TitleizeFilter
28
+ # @param input [String] The String to be filtered
29
+ # @return [String] A new capitalized String
24
30
  def self.evaluate(input)
25
31
  input.kind_of?(String) ? mb_send(:capitalize, input) : input
26
32
  end
@@ -1,31 +1,37 @@
1
1
  module Normatron
2
2
  module Filters
3
+
4
+ ##
5
+ # Remove the given record separator from the end of the string (If present).
6
+ # If @$/@ has not been changed from the default Ruby record separator, then chomp also removes carriage return
7
+ # characters (that is it will remove @\n@, @\r@, and @\r\n@).
8
+ #
9
+ # @example Out of box
10
+ # ChompFilter.evaluate("Bon Scott\n") #=> "Bon Scott"
11
+ # ChompFilter.evaluate("Bon Scott\r") #=> "Bon Scott"
12
+ # ChompFilter.evaluate("Bon Scott\r\n") #=> "Bon Scott"
13
+ # ChompFilter.evaluate("Bon Scott\n\r") #=> "Bon Scott\n"
14
+ # ChompFilter.evaluate("Bon Scott", " Scott") #=> "Bon"
15
+ #
16
+ # @example Using as model normalizer
17
+ # normalize :attribute_a, :with => :chomp
18
+ # normalize :attribute_b, :with => [:custom_filter, :chomp]
19
+ # normalize :attribute_c, :with => [[:chomp, "x"]]
20
+ # normalize :attribute_d, :with => [{:chomp => "y"}]
21
+ # normalize :attribute_e, :with => [:custom_filter, [:chomp, "z"]]
22
+ # normalize :attribute_f, :with => [:custom_filter, {:chomp => "\f"}]
23
+ #
24
+ # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-chomp String#chomp
3
25
  module ChompFilter
4
26
 
5
27
  ##
6
- # Remove the given record separator from the end of the string (If present).
7
- # If <tt>$/</tt> has not been changed from the default Ruby record separator,
8
- # then chomp also removes carriage return characters (that is it will remove <tt>\n</tt>, <tt>\r</tt>, and <tt>\r\n</tt>).
9
- #
10
- # @example
11
- # ChompFilter.evaluate("Bon Scott\n") #=> "Bon Scott"
12
- # ChompFilter.evaluate("Bon Scott\r") #=> "Bon Scott"
13
- # ChompFilter.evaluate("Bon Scott\r\n") #=> "Bon Scott"
14
- # ChompFilter.evaluate("Bon Scott\n\r") #=> "Bon Scott\n"
15
- # ChompFilter.evaluate("Bon Scott", " Scott") #=> "Bon"
28
+ # Performs input conversion according to filter requirements.
16
29
  #
17
- # @example Using as ActiveRecord::Base normalizer
18
- # normalize :attribute_a, :with => :chomp
19
- # normalize :attribute_b, :with => [:custom_filter, :chomp]
20
- # normalize :attribute_c, :with => [[:chomp, "x"]]
21
- # normalize :attribute_d, :with => [{:chomp => "y"}]
22
- # normalize :attribute_e, :with => [:custom_filter, [:chomp, "z"]]
23
- # normalize :attribute_f, :with => [:custom_filter, {:chomp => "\f"}]
30
+ # This method returns the object itself when the first argument is not a String.
24
31
  #
25
- # @param [String] input A character sequence
26
- # @param [String] separator A character sequence
27
- # @return [String] The chopped character sequence or the object itself
28
- # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-chomp String#chomp
32
+ # @param input [String] The String to be filtered
33
+ # @param separator [String] The separator used to chomp input
34
+ # @return [String] A new chopped String
29
35
  def self.evaluate(input, separator=$/)
30
36
  input.kind_of?(String) ? input.chomp(separator) : input
31
37
  end
@@ -2,21 +2,27 @@ require 'normatron/filters/helpers'
2
2
 
3
3
  module Normatron
4
4
  module Filters
5
+
6
+ ##
7
+ # Replaces all underscores with dashes.
8
+ #
9
+ # @example Out of box
10
+ # DasherizeFilter.evaluate("monty_python") #=> "monty-python"
11
+ #
12
+ # @example Using as model normalizer
13
+ # normalize :attribute_a, :with => :dasherize
14
+ # normalize :attribute_b, :with => [:custom_filter, :dasherize]
15
+ #
16
+ # @see http://api.rubyonrails.org/classes/String.html#method-i-dasherize String#dasherize
5
17
  module DasherizeFilter
6
18
 
7
19
  ##
8
- # Replaces all underscores with dashes.
9
- #
10
- # @example
11
- # DasherizeFilter.evaluate("monty_python") #=> "monty-python"
20
+ # Performs input conversion according to filter requirements.
12
21
  #
13
- # @example Using as ActiveRecord::Base normalizer
14
- # normalize :attribute_a, :with => :dasherize
15
- # normalize :attribute_b, :with => [:custom_filter, :dasherize]
22
+ # This method returns the object itself when the first argument is not a String.
16
23
  #
17
- # @param [String] input A character sequence
18
- # @return [String] The dasherized character sequence or the object itself
19
- # @see http://api.rubyonrails.org/classes/String.html#method-i-dasherize String#dasherize
24
+ # @param input [String] The String to be filtered
25
+ # @return [String] A new dasherized String
20
26
  def self.evaluate(input)
21
27
  input.kind_of?(String) ? input.dasherize : input
22
28
  end
@@ -2,25 +2,31 @@ require 'normatron/filters/helpers'
2
2
 
3
3
  module Normatron
4
4
  module Filters
5
+
6
+ ##
7
+ # Lowercase all characters.
8
+ #
9
+ # @example Out of box
10
+ # DowncaseFilter.evaluate("NOTHING ELSE MATTERS") #=> "nothing else matters"
11
+ #
12
+ # @example Using as ActiveRecord::Base normalizer
13
+ # normalize :attribute_a, :with => :downcase
14
+ # normalize :attribute_b, :with => [:custom_filter, :downcase]
15
+ #
16
+ # @see http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Chars.html#method-i-downcase ActiveSupport::Multibyte::Chars#downcase
17
+ # @see SwapcaseFilter Normatron::Filters::SwapcaseFilter
18
+ # @see TitleizeFilter Normatron::Filters::TitleizeFilter
19
+ # @see UpcaseFilter Normatron::Filters::UpcaseFilter
5
20
  module DowncaseFilter
6
21
  extend Helpers
7
22
 
8
23
  ##
9
- # Lowercase all characters.
10
- #
11
- # @example
12
- # DowncaseFilter.evaluate("NOTHING ELSE MATTERS") #=> "nothing else matters"
24
+ # Performs input conversion according to filter requirements.
13
25
  #
14
- # @example Using as ActiveRecord::Base normalizer
15
- # normalize :attribute_a, :with => :downcase
16
- # normalize :attribute_b, :with => [:custom_filter, :downcase]
26
+ # This method returns the object itself when the first argument is not a String.
17
27
  #
18
- # @param [String] input A character sequence
19
- # @return [String] The lowercased character sequence or the object itself
20
- # @see http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Chars.html#method-i-downcase ActiveSupport::Multibyte::Chars#downcase
21
- # @see SwapcaseFilter Normatron::Filters::SwapcaseFilter
22
- # @see TitleizeFilter Normatron::Filters::TitleizeFilter
23
- # @see UpcaseFilter Normatron::Filters::UpcaseFilter
28
+ # @param input [String] The String to be filtered
29
+ # @return [String] A new lowercased String
24
30
  def self.evaluate(input)
25
31
  input.kind_of?(String) ? mb_send(:downcase, input) : input
26
32
  end
@@ -1,24 +1,30 @@
1
1
  module Normatron
2
2
  module Filters
3
+
4
+ ##
5
+ # Creates a literal string representation with all nonprinting characters replaced by @\\n@ notation and all
6
+ # special characters escaped.
7
+ #
8
+ # @example Out of box
9
+ # DumpFilter.evaluate("I'm not\na \"clubber\"...") #=> "\"I'm not\\na \\\"clubber\\\"...\""
10
+ # DumpFilter.evaluate("I'm not\na \"clubber\"...") #== '"I\'m not\na \"clubber\"..."'
11
+ # DumpFilter.evaluate('I\'m not\na "clubber"...') #=> "\"I'm not\\\\na \\\"clubber\\\"...\""
12
+ # DumpFilter.evaluate('I\'m not\na "clubber"...') #== '"I\'m not\\\na \"clubber\"..."'
13
+ #
14
+ # @example Using as ActiveRecord::Base normalizer
15
+ # normalize :attribute_a, :with => :dump
16
+ # normalize :attribute_b, :with => [:custom_filter, :dump]
17
+ #
18
+ # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-dump String#dump
3
19
  module DumpFilter
4
20
 
5
21
  ##
6
- # Creates a literal string representation with all nonprinting characters
7
- # replaced by <tt>\\n</tt> notation and all special characters escaped.
8
- #
9
- # @example
10
- # DumpFilter.evaluate("I'm not\na \"clubber\"...") #=> "\"I'm not\\na \\\"clubber\\\"...\""
11
- # DumpFilter.evaluate("I'm not\na \"clubber\"...") #== '"I\'m not\na \"clubber\"..."'
12
- # DumpFilter.evaluate('I\'m not\na "clubber"...') #=> "\"I'm not\\\\na \\\"clubber\\\"...\""
13
- # DumpFilter.evaluate('I\'m not\na "clubber"...') #== '"I\'m not\\\na \"clubber\"..."'
22
+ # Performs input conversion according to filter requirements.
14
23
  #
15
- # @example Using as ActiveRecord::Base normalizer
16
- # normalize :attribute_a, :with => :dump
17
- # normalize :attribute_b, :with => [:custom_filter, :dump]
24
+ # This method returns the object itself when the first argument is not a String.
18
25
  #
19
- # @param [String] input A character sequence
20
- # @return [String] The dumpped character sequence or the object itself
21
- # @see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-dump String#dump
26
+ # @param input [String] The String to be filtered
27
+ # @return [String] A new dumpped String
22
28
  def self.evaluate(input)
23
29
  input.kind_of?(String) ? input.dump : input
24
30
  end