etsm 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/etsm.rb +74 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3d8b1aed6b7fdcb555f7ec84928a52bd54ce3cf22b448340701fa0f7a320213
4
- data.tar.gz: 330522ee291c74a2dcbdfb7fd69e9e65fe5f057c2c63996a2c99150872ab1985
3
+ metadata.gz: 3d4c3c8e2c09ad34927b52dd4c3fb541e77ce2af08bc253ff2428e36f87c7180
4
+ data.tar.gz: 69c530bbe9e11fdaa4a8790be6f023b0a1f6adbf4be70b9d6d80e5db85fa8fa7
5
5
  SHA512:
6
- metadata.gz: f5006f22326d689391cb43ce1b4b58f53cc8a7fa32fe3e25773767829f7312627e1ffb14e5aea92153b12b34e7a5e1051e22f1c1fd8e5a2e2876e5f0a90c7ddc
7
- data.tar.gz: 186ab968121ca65f8672fad391bb494e72b3d88a55b61399a41a22d007a569759ec48cb5156218f5486b4f6de43cbfc43b141db17fe584f4b1b57fed15d69db7
6
+ metadata.gz: 5025d870aa20dc76f10497a5f0b6cb0f2fcfafdc20a1926d6bba21b26ca15723869517e1f2f78a510ff1739336bc55f1ace7af83a6a3462eeafd7c38be6bdeae
7
+ data.tar.gz: b0875d8e36231402ba101ebc6c6e46f20074f7de6385b03dec93a4c7f0b5b0270748d1039d4842efb4520b87e33f7c37a4f0ef0767c36bfced83407c5a0510d8
data/lib/etsm.rb CHANGED
@@ -1,5 +1,75 @@
1
- class StateMachine
2
- def self.hi
3
- puts "StateMachine!"
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2022 Eric Thiffeault
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+ #
23
+ # <https://github.com/ethiffeault/etsm>
24
+
25
+ module Etsm
26
+
27
+ class State
28
+ attr_reader :enter
29
+ attr_reader :exit
30
+
31
+ def initialize(enter, exit)
32
+ @enter = enter
33
+ @exit = exit
34
+ end
4
35
  end
5
- end
36
+
37
+ class StateMachine
38
+
39
+ attr_reader :owner
40
+ attr_reader :current
41
+ attr_reader :in_transition
42
+
43
+ def initialize(owner)
44
+ @owner = owner
45
+ @current = nil
46
+ @in_transition = false
47
+ end
48
+
49
+ def Transition(state)
50
+ if @in_transition == true
51
+ return false
52
+ end
53
+
54
+ @in_transition = true
55
+
56
+ if @current != nil and @current.exit != nil
57
+ @current.exit.call
58
+ end
59
+
60
+ @current = state
61
+
62
+ if @current != nil and @current.enter != nil
63
+ @current.enter.call
64
+ end
65
+
66
+ @in_transition = false
67
+ return true
68
+ end
69
+
70
+ def IsIn(state)
71
+ return state == @current
72
+ end
73
+
74
+ end
75
+ end # module etsm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Thiffeault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-26 00:00:00.000000000 Z
11
+ date: 2022-05-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Efficient Tiny State Machine using object callbacks
14
14
  email: ethiffeault@gmail.com