Class: ProjectSimulator::Model
- Inherits:
-
Object
- Object
- ProjectSimulator::Model
- Includes:
- AppRoutes
- Defined in:
- lib/projectsimulator.rb
Instance Method Summary collapse
- #build(raw_requests, root: @root) ⇒ Object
- #get_device(h) ⇒ Object
-
#initialize(obj = nil, root: 'building1') ⇒ Model
constructor
A new instance of Model.
- #op ⇒ Object
- #query(s) ⇒ Object
- #request(s) ⇒ Object
- #set_device(h) ⇒ Object
- #to_sliml ⇒ Object
- #xml(options = nil) ⇒ Object
Constructor Details
#initialize(obj = nil, root: 'building1') ⇒ Model
Returns a new instance of Model.
15 16 17 18 19 20 21 22 |
# File 'lib/projectsimulator.rb', line 15 def initialize(obj=nil, root: 'building1') super() @root = root @location = nil build(obj, root: root) if obj end |
Instance Method Details
#build(raw_requests, root: @root) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/projectsimulator.rb', line 24 def build(raw_requests, root: @root) @ed = EasyDom.new(debug: false, root: root) raw_requests.lines.each {|line| request(line) } end |
#get_device(h) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/projectsimulator.rb', line 31 def get_device(h) a = h[:location].split(/ /) a << h[:device] status = a.inject(@ed) {|r,x| r.send(x)}.send(h[:action]) "The %s %s is %s." % [h[:location], h[:device], status] end |
#op ⇒ Object
40 41 42 |
# File 'lib/projectsimulator.rb', line 40 def op() @ed end |
#query(s) ⇒ Object
44 45 46 |
# File 'lib/projectsimulator.rb', line 44 def query(s) @ed.e.element(s) end |
#request(s) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/projectsimulator.rb', line 48 def request(s) params = {request: s} requests(params) h = find_request(s) method(h.first[-1]).call(h) end |
#set_device(h) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/projectsimulator.rb', line 58 def set_device(h) a = h[:location].split(/ /) a << h[:device] a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value]) end |
#to_sliml ⇒ Object
66 67 68 |
# File 'lib/projectsimulator.rb', line 66 def to_sliml() @ed.to_sliml end |
#xml(options = nil) ⇒ Object
70 71 72 |
# File 'lib/projectsimulator.rb', line 70 def xml(=nil) @ed.xml(pretty: true).gsub(' style=\'\'','') end |