moory 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/moory/filter.rb +28 -11
- data/lib/moory/logistic.rb +2 -7
- data/lib/moory/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee957252af324461f5b03d051af8bebc82490f2e7fb0a179b76c516d7c99a24e
|
|
4
|
+
data.tar.gz: 72fde9356fccfc2f8748913b25b4293bbd4468c44ad6c159bf689b06407d0dcd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39b2e02d32bd8392187af62134927118240411b773e099697e1c272be0711f8b6e56691d47d4cad01c754f2810318bf67cee13daceccb0fcf373496f01144f3d
|
|
7
|
+
data.tar.gz: f53f603d96598d899af20b2db88e8faf91991d2f72a5a04c56f78b51ad37a079eea57d848efac174c2c66bb3535460c5c9ec059282d93ddffb7e38908045664c
|
data/Gemfile.lock
CHANGED
data/lib/moory/filter.rb
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
module Moory
|
|
2
2
|
class Filter < Moory::Logistic::Unit
|
|
3
|
+
attr_writer :consumer
|
|
4
|
+
attr_writer :quarantine
|
|
5
|
+
attr_reader :buffer
|
|
6
|
+
|
|
3
7
|
IGNORE = [' ', "\t", "\n"]
|
|
4
8
|
DEFAULT_CONSUMER = $stdout.method(:puts)
|
|
5
|
-
|
|
9
|
+
IGNORE_UNKNOWN = proc { |c| pp "Warning! Ignoring unknown character: #{c}" }
|
|
6
10
|
|
|
7
|
-
def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:
|
|
11
|
+
def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:IGNORE_UNKNOWN)
|
|
8
12
|
@buffer = ""
|
|
9
|
-
@consumer
|
|
13
|
+
@consumer = consumer
|
|
10
14
|
@quarantine = quarantine
|
|
11
|
-
super(rules: rules
|
|
15
|
+
super(rules: rules)
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def configure(rules)
|
|
@@ -16,18 +20,31 @@ module Moory
|
|
|
16
20
|
repertoire.learn(name: 'produce', item: method(:produce))
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
def produce(output)
|
|
20
|
-
@consumer.call(
|
|
21
|
-
@buffer
|
|
22
|
-
)
|
|
23
|
-
@buffer = ""
|
|
24
|
-
end
|
|
25
|
-
|
|
26
23
|
def issue(stimulus)
|
|
27
24
|
return if IGNORE.include?(stimulus)
|
|
28
25
|
|
|
29
26
|
@buffer << stimulus
|
|
30
27
|
super
|
|
31
28
|
end
|
|
29
|
+
|
|
30
|
+
def produce(output)
|
|
31
|
+
consumer.call(@buffer)
|
|
32
|
+
@buffer = ""
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def bad_stimulus(stimulus)
|
|
38
|
+
quarantine.call(stimulus)
|
|
39
|
+
@buffer = @buffer.slice(0..-2)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def consumer
|
|
43
|
+
@consumer || DEFAULT_CONSUMER
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def quarantine
|
|
47
|
+
@quarantine || IGNORE_UNKNOWN
|
|
48
|
+
end
|
|
32
49
|
end
|
|
33
50
|
end
|
data/lib/moory/logistic.rb
CHANGED
|
@@ -9,11 +9,8 @@ module Moory
|
|
|
9
9
|
class Unit
|
|
10
10
|
include Moory::Efferent
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def initialize(rules:, initial:'^',quarantine:nil)
|
|
12
|
+
def initialize(rules:, initial:'^')
|
|
15
13
|
@initial = initial
|
|
16
|
-
@quarantine = quarantine
|
|
17
14
|
configure(rules)
|
|
18
15
|
end
|
|
19
16
|
|
|
@@ -35,9 +32,7 @@ module Moory
|
|
|
35
32
|
end
|
|
36
33
|
|
|
37
34
|
def bad_stimulus(stimulus)
|
|
38
|
-
|
|
39
|
-
quarantine.call(stimulus) :
|
|
40
|
-
(raise "Unexpected #{stimulus}")
|
|
35
|
+
raise "Unexpected #{stimulus}"
|
|
41
36
|
end
|
|
42
37
|
end
|
|
43
38
|
|
data/lib/moory/version.rb
CHANGED