dibnahs_dogs 1.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dibnahs_dogs.rb +373 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80555032bbba33a390f83c0bfd988464762ee4b3
4
+ data.tar.gz: b6ba019e7a23ed459ebec92bf72a177d0abb16bc
5
+ SHA512:
6
+ metadata.gz: 5ceefccfe914b9ce04816427181fb79aec19b7d138506e18cdaecd3fea7f9f916f2f4ed588242aaa066c0a35d003afed8045312e12a2df141c8b7c8b74902975
7
+ data.tar.gz: 81ef6b6a408b956dae2c46da6d0593ed7bc3a2b1731aa9de0c2342a43db392e05ec8f782ccc45347c86562e8f2bdcab47655dc6faff614b5680de0debd1b509a
@@ -0,0 +1,373 @@
1
+ #
2
+ # Dibnahs_Dogs::Activity Modeller::State Machine.rb -
3
+ # $Release Version: 0.2 $
4
+ # $Revision: 1.1.1 $
5
+ # by mark ingram
6
+ #
7
+ # --
8
+ # Run this file for TEST and example use
9
+ # for documentation tips and usage call the <classname>_Doc i.e. SM_Doc
10
+ # for specific function documentation call
11
+ class SM #private donot instantiate rather use StateMachine
12
+ def initialize
13
+ @count = 0 #number of states in the machine
14
+ @state = 0
15
+ end
16
+ attr_reader :count, :state
17
+ def count=(states)
18
+ if states > 0 then @count = states
19
+ self.state = 1
20
+ else
21
+ puts "StateMachine.Count requires one or more states. To clear the states, use StateMachine.Clear."
22
+ end
23
+ end
24
+ def state=(newstate)
25
+ if newstate < 1 then
26
+ puts "StateMachine.State cannot be set less than 1"
27
+ elsif newstate > self.count then puts " StateMachine.State cannot be set greater than StateMachine.Count."
28
+ elsif newstate > 0 and newstate <= self.count then
29
+ @state = newstate
30
+ setState(newstate)
31
+ end
32
+ end
33
+ def setState(newstate)
34
+ self.state = newstate
35
+ end
36
+ def clear
37
+ @count = 0
38
+ @state = 0
39
+ end
40
+ def move(states)
41
+ tmp = 0
42
+ tmp = self.state + states
43
+ if tmp < 1 then state = 1
44
+ end
45
+ if tmp > @count then tmp = @count
46
+ end
47
+ # puts " =8= count #{@count}\nstates #{states}\ntmp#{tmp} \nself.state #{self.state} \n =8="
48
+ self.state = tmp
49
+ puts self.state
50
+ end
51
+ end
52
+ class StateMachine<SM
53
+ def initialize
54
+ @state = 0
55
+ self.count = 4
56
+ end
57
+ def back
58
+ self.move(-1)
59
+ end
60
+ def next
61
+ self.move(1)
62
+ end
63
+ def goto(state)
64
+ self.state = state
65
+ end
66
+ def stateMachineEnd
67
+ puts 'end'
68
+ self.clear
69
+ end
70
+ def setState(state)
71
+ case state
72
+ when state = 1 then action = doOne # action = "this is state one"
73
+ when state = 2 then action = doTwo # "this is state two"
74
+ when state = 3 then action = "This is state three"
75
+ when state = 4 then action = "this is the action for state four"
76
+ else puts "an error prehaps"
77
+ end
78
+ puts action
79
+ end
80
+ def doTwo
81
+ tmp = "this is the stuff that we do at two"
82
+ tmp
83
+ end
84
+ def doOne
85
+ tmp = "The state machine is properly initialised"
86
+ tmp
87
+ end
88
+ end
89
+ class SM_Doc
90
+ def initialize
91
+ puts "SM is just the class holding states and checking for the most basic errors\n you are free to extend it but I would not recommend instanciating it. \n Instead use StateMachine.\n Use the public access functions for state machine fuctionality:\n\t next #state forward\n\t goto # a specific state\n\tback # an number of states \n\tclear #the registers "
92
+ end
93
+ end
94
+ class StateMachine_Doc
95
+ def initialize
96
+ puts "This is my standard state machine.\n Overload the function setState.....because it is here that the state tabel is described and only here"
97
+ end
98
+ end
99
+ class StateDiagram
100
+ def initialize
101
+ @name = "New State Diagram"
102
+ start = InitialState::new
103
+ start.name = "start"
104
+ start.activity = "initialize"
105
+ @Diagram = Array::new
106
+ @Diagram << start
107
+ end
108
+ attr_accessor :name
109
+ def clear
110
+ @Diagram = ""
111
+ end
112
+ def link(parent,child)
113
+ tmp = ""
114
+ @Diagram.each {|a|
115
+ tmp = tmp + "#{a.name} "
116
+ if a.name == parent then
117
+ @Diagram.each {|b|
118
+ if b.name == child
119
+ a.pointsTo = b.serialNo
120
+ tmp = "#{a.name}points to #{b.name}\n"
121
+ end
122
+ }
123
+ end
124
+ }
125
+ tmp
126
+ end
127
+ def addState(name)
128
+ a = State::new
129
+ a.name = name
130
+ a.activity = name
131
+ @Diagram << a
132
+ tmp = ""
133
+ tmp
134
+ end
135
+ def deleteState(name)
136
+ end
137
+ def updateSate(name)
138
+ tmp = "make sure you dont delete any thing that has already been written"
139
+ tmp
140
+ end
141
+ def draw #self.inspect
142
+ tmp = "#{@name}\n\n"
143
+ @Diagram.each {|a|
144
+ tmp = tmp + "#{a.name}(#{a.serialNo}) \n"
145
+ tmp = tmp + "\tpoints to #{a.pointsTo}\n"
146
+ }
147
+ tmp
148
+ end
149
+ def checkSyntax
150
+ tmp = "Check that there is just one start one finish and that all the activities have children"
151
+ end
152
+ def toRuby
153
+ # tmp = "#generate the Mile StateMachine Code\n\nrequire \"MILE/BIN/StateMachine\"\n"
154
+ # tmp = "#generate the Mile StateMachine Code\n\nrequire \"./StateMachine\"\n"
155
+ tmp = "#generate the Mile StateMachine Code\n\nrequire \"dibnahs_dogs\"\n"
156
+ tmp = tmp + "class #{@name}<StateMachine\n def initialize \n\t#{makeHash}\n @state = 0\n self.count = #{@Diagram.size}\n end\n def setState(state)\n case state\n#{makeWhen} else puts \"state not found error\"\n end\n puts action\n end\n #{makeAction}end\n"
157
+ tmp
158
+ end
159
+ def makeHash
160
+ tmp = " @hash = {\n\t"
161
+ @Diagram.each { |a|
162
+ tmp = tmp + " '#{a.activity}' => #{a.serialNo},\n\t"
163
+ }
164
+ #REMOVE THE LAST , /\,/Start from the right =8=
165
+ tmp = tmp + "\t} "
166
+ tmp
167
+ end
168
+ def makeWhen
169
+ tmp = ""
170
+ @Diagram.each { |a|
171
+ tmp = tmp + "\twhen state = @hash['#{a.activity}'] then action = #{a.activity}\n"
172
+ }
173
+ tmp
174
+ end
175
+ def makeAction
176
+ tmp = ""
177
+ @Diagram.each { |a|
178
+ tmp = tmp + " def #{a.activity}\n tmp = \"This is where we do state_#{a.name} functionality\"\n tmp\n end\n"
179
+ }
180
+ tmp
181
+ end
182
+ public #:method1, :method4
183
+ protected #:method2
184
+ private :makeHash ,:makeWhen ,:makeAction
185
+ end
186
+ class Node
187
+ @@id = 0
188
+ def initialize
189
+ @@id = @@id + 1
190
+ @serialNo = @@id
191
+ @child = @serialNo
192
+ end
193
+ attr_reader :serialNo, :child
194
+ attr_writer :child
195
+ end
196
+ class State<Node
197
+ @name = ""
198
+ @activity = ""
199
+ attr_reader :name, :activity
200
+ attr_writer :name, :activity
201
+ def pointsTo
202
+ return self.child
203
+ end
204
+ def pointsTo=(serialNo)
205
+ self.child = serialNo
206
+ end
207
+ end
208
+ class InitialState<State #symbol is the black blob see Rose
209
+
210
+ end
211
+ class FinishedState<State #symbol is the black blob and black ring see Rose
212
+ end
213
+ class ActivityDiagram <StateDiagram
214
+ def initialize
215
+ # =8= 27022004 self.name = "New_Activity_Diagram"
216
+ @name = "New_Activity_Diagram"
217
+ @Diagram = Array::new
218
+ end
219
+ def clear
220
+ @Diagram = ""
221
+ end
222
+ def addActivity(name,functionality,documentation)
223
+ a = Activity::new
224
+ a.name = name
225
+ a.activity = name # the name of the function called in set_State
226
+ a.functionality = functionality #the contents of the function above
227
+ a.documentation = documentation
228
+ @Diagram << a
229
+ tmp = ""
230
+ tmp
231
+ end
232
+ def addInitiator
233
+ self.addActivity("initiator","","")
234
+ end
235
+ def addAccomplishment
236
+ self.addActivity("accomplishment","self.clear","")
237
+ #self.link("accomplishment","initiator","")
238
+ end
239
+ def link(parent,child, condition)
240
+ tmp = ""
241
+ @Diagram.each {|a|
242
+ tmp = tmp + "#{a.name} "
243
+ if a.name == parent then
244
+ @Diagram.each {|b|
245
+ if b.name == child then
246
+ if a.instance_of?(Decision)then
247
+ a.pointsTo = ["#{b.serialNo}","#{condition}"]
248
+ tmp = "#{a.name}points to #{b.name}\n"
249
+ else
250
+ a.pointsTo = b.serialNo
251
+ end
252
+ end
253
+ }
254
+ end
255
+ }
256
+ tmp
257
+ end
258
+ def addDecision(name,documentation)
259
+ a = Decision::new
260
+ a.name = name
261
+ a.activity = name
262
+ a.documentation = documentation
263
+ @Diagram << a
264
+ tmp = ""
265
+ tmp
266
+ end
267
+ def makeWhen
268
+ tmp = ""
269
+ @Diagram.each { |a|
270
+ tmp += "\twhen state = @hash['#{a.activity}'] then action = #{a.activity}\n"
271
+ }
272
+ tmp
273
+ end
274
+ def makeHash
275
+ tmp = " @hash = {\n\t"
276
+ tmp1 = ""
277
+ @Diagram.each { |a|
278
+ tmp += "#{tmp1}\t\t '#{a.activity}' => #{a.serialNo}"
279
+ tmp1 = ",\n"
280
+ }
281
+ tmp += "\n\t} "
282
+ tmp
283
+ end
284
+ def makeAction
285
+ tmp = ""
286
+ @Diagram.each { |a|
287
+ tmp += "\tdef #{a.activity}\n"
288
+ tmp1 = ""
289
+ if a.instance_of?(Decision)then
290
+ tmp += "if"
291
+ a.pointsTo.each{|b|
292
+ tmp += "#{tmp1} #{b.at(1)} then \n\tself.goto(#{b.at(0)})\n"
293
+ tmp1 = "elsif"
294
+ }
295
+ tmp += "end\n"
296
+ else
297
+ tmp += "\t #{a.functionality}\n"
298
+ unless a.pointsTo == a.serialNo #or a.instance_of?(Decision) then #infinite loop ;)
299
+ tmp += "\t self.goto(#{a.pointsTo})\n"
300
+ else
301
+ end
302
+ end
303
+ tmp += "end\n"
304
+ }
305
+ tmp
306
+ end
307
+ def draw #self.inspect
308
+ tmp = "#{@name}\n\n"
309
+ @Diagram.each {|a|
310
+ tmp += "#{a.name}(#{a.serialNo}) \n"
311
+ if a.instance_of?(Decision) then
312
+ a.pointsTo.each{|b|
313
+ tmp += "\tpoints to #{b.at(0)} if #{b.at(1)}\n"
314
+ }
315
+ else
316
+ tmp += "\tpoints to #{a.pointsTo}\n"
317
+ end
318
+ }
319
+ tmp
320
+ end
321
+ public :addDecision, :addActivity
322
+ private :addState
323
+ end
324
+ class Activity<State
325
+ def initalize
326
+ super
327
+ @functionality = ""
328
+ @documentation = ""
329
+ end
330
+ attr_reader :functionality, :documentation
331
+ attr_writer :functionality, :documentation
332
+ end
333
+ class Decision<Activity
334
+ def initialize
335
+ super
336
+ @child = []
337
+ end
338
+ def pointsTo=(arr)
339
+ self.child << arr
340
+ end
341
+ end
342
+ class DibnahsDogs<ActivityDiagram
343
+ end
344
+ # Unit Test
345
+ if $0 == __FILE__ then
346
+ b = DibnahsDogs::new
347
+ b.name = "Test1"
348
+ b.addInitiator
349
+ b.addActivity("activity_1","puts \"yo 1 \"\n","\t qwertet\n\n")
350
+ b.addActivity("activity_2","puts \"yo 2 \"\n","\t qwertet\n\n")
351
+ b.addActivity("activity_3","puts \"yo 3 \"\n","\t qwertet\n\n")
352
+ b.addActivity("activity_4","puts \"yo 4 \"\n","\t qwertet\n\n")
353
+ b.addDecision("decision1","This is where we decide what to do\n")
354
+ b.addActivity("activity_5","puts \"yo 5 \"\n","\t qwertet\n\n")
355
+ b.addActivity("activity_6","puts \"yo 6 \"\n","\t qwertet\n\n")
356
+ b.addAccomplishment
357
+ b.link("initiator","activity_1","")
358
+ b.link("activity_1","activity_3","")
359
+ b.link("activity_3","activity_2","")
360
+ b.link("activity_2","activity_4","")
361
+ b.link("activity_4","decision1","")
362
+ b.link("activity_5","accomplishment","")
363
+ b.link("activity_6","activity_5","")
364
+ b.link("decision1","activity_5","false")
365
+ b.link("decision1","accomplishment","false")
366
+ b.link("decision1","activity_6", "true")
367
+ ##puts b.inspect
368
+ ##puts b.draw
369
+ tmp2 = b.toRuby
370
+ tmp2 += "puts a = Test1.new"
371
+ puts tmp2
372
+ instance_eval tmp2
373
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dibnahs_dogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - mark ingram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email:
15
+ - m.ingram@computer.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/dibnahs_dogs.rb
21
+ homepage:
22
+ licenses:
23
+ - Ruby
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.8
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Actvity Modelling with simple state machine
45
+ test_files: []