Class: Dap::Filter::FilterTransform

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/dap/filter/simple.rb

Instance Attribute Summary

Attributes included from Base

#name, #opts

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#process(doc) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/dap/filter/simple.rb', line 143

def process(doc)
  self.opts.each_pair do |k,v|
    if doc.has_key?(k)
      case v
      when 'downcase'
        doc[k] = doc[k].to_s.downcase
      when 'upcase'
        doc[k] = doc[k].to_s.upcase
      when 'ascii'
        doc[k] = doc[k].to_s.gsub(/[\x00-\x1f\x7f-\xff]/n, '')
      when 'utf8encode'
        doc[k] = doc[k].to_s.encode!('UTF-8', invalid: :replace, undef: :replace, replace: '')
      when 'base64decode'
        doc[k] = doc[k].to_s.unpack('m*').first
      when 'base64encode'
        doc[k] = [doc[k].to_s].pack('m*').gsub(/\s+/n, '')
      when 'qprintdecode'
        doc[k] = doc[k].to_s.gsub(/=([0-9A-Fa-f]{2})/n){ |x| [x[1,2]].pack("H*") }
      when 'qprintencode'
        doc[k] = doc[k].to_s.gsub(/[\x00-\x20\x3d\x7f-\xff]/n){|x| ( "=%.2x" % x.unpack("C").first ).upcase }
      when 'hexdecode'
        doc[k] = [ doc[k].to_s ].pack("H*")
      when 'hexencode'
        doc[k] = doc[k].to_s.unpack("H*").first
      end
    end
  end
 [ doc ]
end