projectsimulator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/projectsimulator.rb +62 -18
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e2aac79d4eedf850b1a69fd68c5ca4dea570e3f29b7c58ba08929b39ff6da6
|
4
|
+
data.tar.gz: 7fcbd8da672a655223aa6fe5fedd6fe3ec5eaa167390163fd4f93c805859d028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c14beebb3a964700e458e9f910d647efb1e5df8135444d5fb5a7701e9af3a67148c5bcd7ef60b00bd158a91b2fe86031189dc5087046f46a146bccd2f6f88f8a
|
7
|
+
data.tar.gz: 516649266578dc2aefbc924e750dab05ab42dcb1e225ac079d80d28d227a247cf4db024239fa4b90cc4b725c352ddcc774ef1e7e63bcad2cf018590f28086cb0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/projectsimulator.rb
CHANGED
@@ -11,18 +11,30 @@ module ProjectSimulator
|
|
11
11
|
class Model
|
12
12
|
include AppRoutes
|
13
13
|
|
14
|
-
def initialize()
|
14
|
+
def initialize(obj=nil, root: 'building1')
|
15
15
|
|
16
|
-
super()
|
16
|
+
super()
|
17
|
+
@root = root
|
18
|
+
@location = nil
|
19
|
+
build(obj, root: root) if obj
|
17
20
|
|
18
21
|
end
|
19
22
|
|
20
|
-
def build(raw_requests, root:
|
23
|
+
def build(raw_requests, root: @root)
|
21
24
|
|
22
25
|
@ed = EasyDom.new(debug: false, root: root)
|
23
26
|
raw_requests.lines.each {|line| request(line) }
|
24
27
|
|
25
28
|
end
|
29
|
+
|
30
|
+
def get_device(h)
|
31
|
+
|
32
|
+
a = h[:location].split(/ /)
|
33
|
+
a << h[:device]
|
34
|
+
status = a.inject(@ed) {|r,x| r.send(x)}.send(h[:action])
|
35
|
+
"The %s %s is %s." % [h[:location], h[:device], status]
|
36
|
+
|
37
|
+
end
|
26
38
|
|
27
39
|
def op()
|
28
40
|
@ed
|
@@ -31,6 +43,24 @@ module ProjectSimulator
|
|
31
43
|
def query(s)
|
32
44
|
@ed.e.element(s)
|
33
45
|
end
|
46
|
+
|
47
|
+
def request(s)
|
48
|
+
|
49
|
+
params = {request: s}
|
50
|
+
requests(@params)
|
51
|
+
h = find_request(s)
|
52
|
+
|
53
|
+
method(h.first[-1]).call(h)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_device(h)
|
58
|
+
|
59
|
+
a = h[:location].split(/ /)
|
60
|
+
a << h[:device]
|
61
|
+
a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value])
|
62
|
+
|
63
|
+
end
|
34
64
|
|
35
65
|
def to_sliml()
|
36
66
|
@ed.to_sliml
|
@@ -44,28 +74,42 @@ module ProjectSimulator
|
|
44
74
|
|
45
75
|
def requests(params)
|
46
76
|
|
77
|
+
# e.g. switch the livingroom gas_fire off
|
78
|
+
#
|
47
79
|
get /(?:switch|turn) the ([^ ]+) +([^ ]+) +(on|off)$/ do |location, device, onoff|
|
48
|
-
{action: 'switch=', location: location, device: device, value: onoff}
|
80
|
+
{type: :set_device, action: 'switch=', location: location, device: device, value: onoff}
|
49
81
|
end
|
82
|
+
|
83
|
+
# e.g. switch the gas _fire off
|
84
|
+
#
|
85
|
+
get /(?:switch|turn) the ([^ ]+) +(on|off)$/ do |device, onoff|
|
86
|
+
location = dev_location(device)
|
87
|
+
{type: :set_device, action: 'switch=', location: location, device: device, value: onoff}
|
88
|
+
end
|
89
|
+
|
90
|
+
# e.g. is the livingroom gas_fire on?
|
91
|
+
#
|
92
|
+
get /is the ([^ ]+) +([^ ]+) +(?:on|off)\??$/ do |location, device|
|
93
|
+
{type: :get_device, action: 'switch', location: location, device: device}
|
94
|
+
end
|
95
|
+
|
96
|
+
# e.g. is the gas_fire on?
|
97
|
+
#
|
98
|
+
get /is the ([^ ]+) +(?:on|off)\??$/ do |device|
|
99
|
+
location = dev_location(device)
|
100
|
+
{type: :get_device, action: 'switch', location: location, device: device}
|
101
|
+
end
|
50
102
|
|
51
103
|
end
|
52
104
|
|
53
105
|
private
|
54
106
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
a = h[:location].split(/ /)
|
62
|
-
a << h[:device]
|
63
|
-
a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value])
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
alias find_request run_route
|
68
|
-
|
107
|
+
def dev_location(device)
|
108
|
+
a = query('//'+ device).backtrack.to_xpath.split('/')
|
109
|
+
a[1..-2].join(' ')
|
110
|
+
end
|
111
|
+
|
112
|
+
alias find_request run_route
|
69
113
|
|
70
114
|
end
|
71
115
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|