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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2662d6b7f7ae172660dfa5c3b29decd7e94897b145f803cf02e1c0c108118159
4
- data.tar.gz: 3fed192e34ac0ef969ad661ee2c796453caee5901677ca19a859565fee45a55c
3
+ metadata.gz: ee957252af324461f5b03d051af8bebc82490f2e7fb0a179b76c516d7c99a24e
4
+ data.tar.gz: 72fde9356fccfc2f8748913b25b4293bbd4468c44ad6c159bf689b06407d0dcd
5
5
  SHA512:
6
- metadata.gz: cd7db2d215cdb870ab22e2898dc86d10c5e162d438e325cadc7eae0e5241c83db3cfbd447f3665673244c84707c1bd6925fff12ed5b81d2536f51a944e3596af
7
- data.tar.gz: 1d48e83ff1f11b1cb6dc22464f745b7aef70eeb4a0274ab3d34ad91ea3ae1ce61f928fbf5a70f95d6de62ea758df81820a3f4e3c9f71203d8aa1d0904f52a9ac
6
+ metadata.gz: 39b2e02d32bd8392187af62134927118240411b773e099697e1c272be0711f8b6e56691d47d4cad01c754f2810318bf67cee13daceccb0fcf373496f01144f3d
7
+ data.tar.gz: f53f603d96598d899af20b2db88e8faf91991d2f72a5a04c56f78b51ad37a079eea57d848efac174c2c66bb3535460c5c9ec059282d93ddffb7e38908045664c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moory (1.2.4)
4
+ moory (1.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- IGNORE_FOREIGN = proc { |c| "Warning! Ignoring unknown character: #{c}" }
9
+ IGNORE_UNKNOWN = proc { |c| pp "Warning! Ignoring unknown character: #{c}" }
6
10
 
7
- def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:IGNORE_FOREIGN)
11
+ def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:IGNORE_UNKNOWN)
8
12
  @buffer = ""
9
- @consumer = consumer
13
+ @consumer = consumer
10
14
  @quarantine = quarantine
11
- super(rules: rules, quarantine:quarantine)
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
@@ -9,11 +9,8 @@ module Moory
9
9
  class Unit
10
10
  include Moory::Efferent
11
11
 
12
- attr_accessor :quarantine
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
- quarantine ?
39
- quarantine.call(stimulus) :
40
- (raise "Unexpected #{stimulus}")
35
+ raise "Unexpected #{stimulus}"
41
36
  end
42
37
  end
43
38
 
@@ -1,3 +1,3 @@
1
1
  module Moory
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam W. Grant