Class: Net::LDAP::FilterParser
- Inherits:
-
Object
- Object
- Net::LDAP::FilterParser
- Defined in:
- lib/net/ldap/filter.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
-
#initialize(str) ⇒ FilterParser
constructor
A new instance of FilterParser.
- #parse(scanner) ⇒ Object
- #parse_filter_branch(scanner) ⇒ Object
- #parse_paren_expression(scanner) ⇒ Object
Constructor Details
#initialize(str) ⇒ FilterParser
Returns a new instance of FilterParser.
299 300 301 302 |
# File 'lib/net/ldap/filter.rb', line 299 def initialize str require 'strscan' @filter = parse( StringScanner.new( str )) or raise Net::LDAP::LdapError.new( "invalid filter syntax" ) end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
297 298 299 |
# File 'lib/net/ldap/filter.rb', line 297 def filter @filter end |
Instance Method Details
#parse(scanner) ⇒ Object
304 305 306 |
# File 'lib/net/ldap/filter.rb', line 304 def parse scanner parse_filter_branch(scanner) or parse_paren_expression(scanner) end |
#parse_filter_branch(scanner) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/net/ldap/filter.rb', line 352 def parse_filter_branch scanner scanner.scan /\s*/ if token = scanner.scan( /[\w\-_]+/ ) scanner.scan /\s*/ if op = scanner.scan( /\=|\<\=|\<|\>\=|\>|\!\=/ ) scanner.scan /\s*/ if value = scanner.scan( /[\w\*\.]+/ ) case op when "=" Filter.eq( token, value ) when "!=" Filter.ne( token, value ) when "<" Filter.lt( token, value ) when "<=" Filter.le( token, value ) when ">" Filter.gt( token, value ) when ">=" Filter.ge( token, value ) end end end end end |
#parse_paren_expression(scanner) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/net/ldap/filter.rb', line 308 def parse_paren_expression scanner if scanner.scan /\s*\(\s*/ b = if scanner.scan /\s*\&\s*/ a = nil branches = [] while br = parse_paren_expression(scanner) branches << br end if branches.length >= 2 a = branches.shift while branches.length > 0 a = a & branches.shift end a end elsif scanner.scan /\s*\|\s*/ # TODO: DRY! a = nil branches = [] while br = parse_paren_expression(scanner) branches << br end if branches.length >= 2 a = branches.shift while branches.length > 0 a = a | branches.shift end a end elsif scanner.scan /\s*\!\s*/ br = parse_paren_expression(scanner) if br ~ br end else parse_filter_branch( scanner ) end if b and scanner.scan( /\s*\)\s*/ ) b end end end |