Class: RegexCleaner
- Defined in:
- lib/suds/cleaner/regex_cleaner.rb
Constant Summary collapse
- EMAIL_REGEX =
/^[a-zA-Z0-9_.+\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/
Instance Attribute Summary collapse
-
#regex_map ⇒ Object
Returns the value of attribute regex_map.
Attributes inherited from Cleaner
Instance Method Summary collapse
- #clean(data) ⇒ Object
-
#initialize(regex_map, destroy_row: false) ⇒ RegexCleaner
constructor
A new instance of RegexCleaner.
Methods inherited from Cleaner
Constructor Details
#initialize(regex_map, destroy_row: false) ⇒ RegexCleaner
Returns a new instance of RegexCleaner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/suds/cleaner/regex_cleaner.rb', line 7 def initialize regex_map, destroy_row: false @regex_map = {} regex_map.each do |column,regex| if Array === column column.each do |col| @regex_map[col] = regex end else @regex_map[column] = regex end end @columns = @regex_map.keys.map(&:to_s) @destroy_row = destroy_row end |
Instance Attribute Details
#regex_map ⇒ Object
Returns the value of attribute regex_map.
4 5 6 |
# File 'lib/suds/cleaner/regex_cleaner.rb', line 4 def regex_map @regex_map end |
Instance Method Details
#clean(data) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/suds/cleaner/regex_cleaner.rb', line 22 def clean data ret_data = data.select do |row| save_row = true row.keys.each do |key| if @regex_map[key] if !(row[key].to_s =~ @regex_map[key]) if @destroy_row save_row = false else row.delete key end end end end save_row # for select end return ret_data end |