Class: CDMDEXER::RegexFilterCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/cdmdexer/regex_filter_callback.rb

Overview

Search an OAI ListSets field using a regular expression

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field: 'setName', pattern: /.*/, inclusive: true) ⇒ RegexFilterCallback

Returns a new instance of RegexFilterCallback.



5
6
7
8
9
# File 'lib/cdmdexer/regex_filter_callback.rb', line 5

def initialize(field: 'setName', pattern: /.*/, inclusive: true)
  @field     = field
  @pattern   = pattern
  @inclusive = inclusive
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



4
5
6
# File 'lib/cdmdexer/regex_filter_callback.rb', line 4

def field
  @field
end

#inclusiveObject (readonly)

Returns the value of attribute inclusive.



4
5
6
# File 'lib/cdmdexer/regex_filter_callback.rb', line 4

def inclusive
  @inclusive
end

#patternObject (readonly)

Returns the value of attribute pattern.



4
5
6
# File 'lib/cdmdexer/regex_filter_callback.rb', line 4

def pattern
  @pattern
end

Instance Method Details

#matches?(set) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/cdmdexer/regex_filter_callback.rb', line 15

def matches?(set)
  pattern.match?(set[field])
end

#valid?(set: {}) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/cdmdexer/regex_filter_callback.rb', line 11

def valid?(set: {})
  inclusive ? matches?(set) : !matches?(set)
end