Class: Ldaptic::Filter::Hash
Overview
A hash is the most general and most useful type of filter builder.
Ldaptic::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.
Ldaptic::Filter(:givenName => "Dav*", :* => true).to_s # => "(givenName=Dav*)"
Instance Attribute Summary collapse
-
#escape_asterisks ⇒ Object
Returns the value of attribute escape_asterisks.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Hash
constructor
Call Ldaptic::Filter(hash) instead of instantiating this class directly.
- #process ⇒ Object
Methods inherited from Abstract
#&, #inspect, #to_ber, #to_net_ldap_filter, #to_s, #|, #~
Constructor Details
#initialize(hash) ⇒ Hash
Call Ldaptic::Filter(hash) instead of instantiating this class directly.
194 195 196 197 |
# File 'lib/ldaptic/filter.rb', line 194 def initialize(hash) @hash = hash.dup @escape_asterisks = !@hash.delete(:*) end |
Instance Attribute Details
#escape_asterisks ⇒ Object
Returns the value of attribute escape_asterisks.
190 191 192 |
# File 'lib/ldaptic/filter.rb', line 190 def escape_asterisks @escape_asterisks end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
191 192 193 |
# File 'lib/ldaptic/filter.rb', line 191 def hash @hash end |
Instance Method Details
#process ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ldaptic/filter.rb', line 199 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 |