Class: Moory::Filter
- Inherits:
-
Logistic::Unit
- Object
- Logistic::Unit
- Moory::Filter
- Defined in:
- lib/moory/filter.rb
Constant Summary collapse
- IGNORE =
[' ', "\t", "\n"]
- DEFAULT_CONSUMER =
$stdout.method(:puts)
- IGNORE_UNKNOWN =
proc { |c| pp "Warning! Ignoring unknown character: #{c}" }
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#consumer ⇒ Object
writeonly
Sets the attribute consumer.
-
#quarantine ⇒ Object
writeonly
Sets the attribute quarantine.
Attributes included from Efferent
Attributes included from Afferent
Instance Method Summary collapse
- #configure(rules) ⇒ Object
-
#initialize(rules:, consumer: DEFAULT_CONSUMER, quarantine: IGNORE_UNKNOWN) ⇒ Filter
constructor
A new instance of Filter.
- #issue(stimulus) ⇒ Object
- #produce(output) ⇒ Object
Methods inherited from Logistic::Unit
Methods included from Afferent
Constructor Details
#initialize(rules:, consumer: DEFAULT_CONSUMER, quarantine: IGNORE_UNKNOWN) ⇒ Filter
Returns a new instance of Filter.
11 12 13 14 15 16 |
# File 'lib/moory/filter.rb', line 11 def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:IGNORE_UNKNOWN) @buffer = "" @consumer = consumer @quarantine = quarantine super(rules: rules) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
5 6 7 |
# File 'lib/moory/filter.rb', line 5 def buffer @buffer end |
#consumer=(value) ⇒ Object
Sets the attribute consumer
3 4 5 |
# File 'lib/moory/filter.rb', line 3 def consumer=(value) @consumer = value end |
#quarantine=(value) ⇒ Object
Sets the attribute quarantine
4 5 6 |
# File 'lib/moory/filter.rb', line 4 def quarantine=(value) @quarantine = value end |
Instance Method Details
#configure(rules) ⇒ Object
18 19 20 21 |
# File 'lib/moory/filter.rb', line 18 def configure(rules) super repertoire.learn(name: 'produce', item: method(:produce)) end |
#issue(stimulus) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/moory/filter.rb', line 23 def issue(stimulus) return if IGNORE.include?(stimulus) @buffer << stimulus super end |
#produce(output) ⇒ Object
30 31 32 33 |
# File 'lib/moory/filter.rb', line 30 def produce(output) consumer.call(@buffer) @buffer = "" end |