Sha256: 302e51e800b215c43271bdba724bf94d7097e573e7b357e3f13a6136e0411497

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Filters
  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

  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

  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

  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

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
livr-0.0.2 lib/LIVR/Rules/Filters.rb