Class: Treequel::Filter::Component

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Defined in:
lib/treequel/filter.rb

Overview

An abstract class for filter components. Subclass and override #to_s to implement a custom Component class.

Direct Known Subclasses

AndComponent, ItemComponent, NotComponent, OrComponent

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(klass) ⇒ Object

Inherited hook: re-expose inheriting class’s .new method



97
98
99
100
# File 'lib/treequel/filter.rb', line 97

def self::inherited( klass )
  klass.module_eval( 'public_class_method :new' )
  super
end

Instance Method Details

#inspectObject

Return a human-readable string representation of the component suitable for debugging.



114
115
116
117
118
119
120
# File 'lib/treequel/filter.rb', line 114

def inspect
  return %Q{#<%s:0x%0x "%s">} % [
    self.class.name,
    self.object_id * 2,
    self.to_s,
  ]
end

#promiscuous?Boolean

Components are non-promiscuous (don’t match everything) by default.

Returns:

  • (Boolean)


123
124
125
# File 'lib/treequel/filter.rb', line 123

def promiscuous?
  return false
end

#to_sObject

Stringify the component. :TODO: If this doesn’t end up being a refactored version of all of its subclasses’s #to_s methods, test that it needs overriding.

Raises:

  • (NotImplementedError)


106
107
108
109
# File 'lib/treequel/filter.rb', line 106

def to_s
  raise NotImplementedError, "%s does not provide an implementation of #to_s" %
    [ self.class.name ]
end