Module: Filters
- Defined in:
- lib/LIVR/Rules/Filters.rb
Class Method Summary collapse
- .leave_only(args) ⇒ Object
- .remove(args) ⇒ Object
- .to_lc(args) ⇒ Object
- .to_uc(args) ⇒ Object
- .trim(args) ⇒ Object
Class Method Details
.leave_only(args) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/LIVR/Rules/Filters.rb', line 35 def self.leave_only(args) chars = args.shift lambda do |value, unuse, output| return if value.nil? or value.eql?('') or not value.kind_of? String output.push(value.gsub(/[^#{Regexp.escape(chars)}]/, '')) return nil end end |
.remove(args) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/LIVR/Rules/Filters.rb', line 26 def self.remove(args) chars = args.shift lambda do |value, unuse, output| return if value.nil? or value.eql?('') or not value.kind_of? String output.push(value.gsub(/[#{Regexp.escape(chars)}]/, '')) return nil end end |
.to_lc(args) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/LIVR/Rules/Filters.rb', line 10 def self.to_lc(args) lambda do |value, unuse, output| return if value.nil? or value.eql?('') or not value.kind_of? String output.push(value.downcase!) return nil end end |
.to_uc(args) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/LIVR/Rules/Filters.rb', line 18 def self.to_uc(args) lambda do |value, unuse, output| return if value.nil? or value.eql?('') or not value.kind_of? String output.push(value.upcase!) return nil end end |
.trim(args) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/LIVR/Rules/Filters.rb', line 2 def self.trim(args) lambda do |value, unuse, output| return if value.nil? or value.eql?('') or not value.kind_of? String output.push(value.strip! || value) return nil end end |