# File lib/net/ldap/filter.rb, line 182
182:   def to_ber
183:     case @op
184:     when :eq
185:       if @right == "*"          # present
186:         @left.to_s.to_ber_contextspecific 7
187:       elsif @right =~ /[\*]/    #substring
188:         ary = @right.split( /[\*]+/ )
189:         final_star = @right =~ /[\*]$/
190:         initial_star = ary.first == "" and ary.shift
191: 
192:         seq = []
193:         unless initial_star
194:           seq << ary.shift.to_ber_contextspecific(0)
195:         end
196:         n_any_strings = ary.length - (final_star ? 0 : 1)
197:         #p n_any_strings
198:         n_any_strings.times {
199:           seq << ary.shift.to_ber_contextspecific(1)
200:         }
201:         unless final_star
202:           seq << ary.shift.to_ber_contextspecific(2)
203:         end
204:         [@left.to_s.to_ber, seq.to_ber].to_ber_contextspecific 4
205:       else                      #equality
206:         [@left.to_s.to_ber, @right.to_ber].to_ber_contextspecific 3
207:       end
208:     when :ge
209:       [@left.to_s.to_ber, @right.to_ber].to_ber_contextspecific 5
210:     when :le
211:       [@left.to_s.to_ber, @right.to_ber].to_ber_contextspecific 6
212:     when :and
213:       ary = [@left.coalesce(:and), @right.coalesce(:and)].flatten
214:       ary.map {|a| a.to_ber}.to_ber_contextspecific( 0 )
215:     when :or
216:       ary = [@left.coalesce(:or), @right.coalesce(:or)].flatten
217:       ary.map {|a| a.to_ber}.to_ber_contextspecific( 1 )
218:     when :not
219:         [@left.to_ber].to_ber_contextspecific 2
220:     else
221:       # ERROR, we'll return objectclass=* to keep things from blowing up,
222:       # but that ain't a good answer and we need to kick out an error of some kind.
223:       raise "unimplemented search filter"
224:     end
225:   end