Class: LDAP::Filter::Hash
Overview
A hash is the most general and most useful type of filter builder.
LDAP::Filter(
:givenName => "David",
:sn! => "Thomas",
:postalCode => (70000..80000)
).to_s # => "(&(givenName=David)(&(postalCode>=70000)(postalCode<=80000))(!(sn=Thomas)))"
Including :* => true allows asterisks to pass through unaltered. Otherwise, they are escaped.
LDAP::Filter(:givenName => "Dav*", :* => true).to_s # => "(givenName=Dav*)"
Instance Attribute Summary (collapse)
-
- (Object) escape_asterisks
Returns the value of attribute escape_asterisks.
-
- (Object) hash
readonly
Returns the value of attribute hash.
Instance Method Summary (collapse)
-
- (Hash) initialize(hash)
constructor
Call LDAP::Filter(hash) instead of instantiating this class directly.
- - (Object) process
Methods inherited from Abstract
#&, #inspect, #to_ber, #to_net_ldap_filter, #to_s, #|, #~
Constructor Details
- (Hash) initialize(hash)
Call LDAP::Filter(hash) instead of instantiating this class directly.
193 194 195 196 |
# File 'lib/ldap/filter.rb', line 193 def initialize(hash) @hash = hash.dup @escape_asterisks = !@hash.delete(:*) end |
Instance Attribute Details
- (Object) escape_asterisks
Returns the value of attribute escape_asterisks
190 191 192 |
# File 'lib/ldap/filter.rb', line 190 def escape_asterisks @escape_asterisks end |
- (Object) hash (readonly)
Returns the value of attribute hash
191 192 193 |
# File 'lib/ldap/filter.rb', line 191 def hash @hash end |
Instance Method Details
- (Object) process
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/ldap/filter.rb', line 198 def process string = @hash.map {|k,v| [k.to_s,v]}.sort.map do |(k,v)| Pair.new(k,v,@escape_asterisks ? "==" : "=~").process end.join case @hash.size when 0 then nil when 1 then string else "(&#{string})" end end |