etsm 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etsm.rb +74 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4c3c8e2c09ad34927b52dd4c3fb541e77ce2af08bc253ff2428e36f87c7180
|
4
|
+
data.tar.gz: 69c530bbe9e11fdaa4a8790be6f023b0a1f6adbf4be70b9d6d80e5db85fa8fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5025d870aa20dc76f10497a5f0b6cb0f2fcfafdc20a1926d6bba21b26ca15723869517e1f2f78a510ff1739336bc55f1ace7af83a6a3462eeafd7c38be6bdeae
|
7
|
+
data.tar.gz: b0875d8e36231402ba101ebc6c6e46f20074f7de6385b03dec93a4c7f0b5b0270748d1039d4842efb4520b87e33f7c37a4f0ef0767c36bfced83407c5a0510d8
|
data/lib/etsm.rb
CHANGED
@@ -1,5 +1,75 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
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.
|
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-
|
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
|