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.
16 17 18 19 20 21 22 23 |
# File 'lib/projectsimulator.rb', line 16 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
25 26 27 28 29 30 |
# File 'lib/projectsimulator.rb', line 25 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
32 33 34 35 36 37 38 39 |
# File 'lib/projectsimulator.rb', line 32 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
41 42 43 |
# File 'lib/projectsimulator.rb', line 41 def op() @ed end |
#query(s) ⇒ Object
45 46 47 |
# File 'lib/projectsimulator.rb', line 45 def query(s) @ed.e.element(s) end |
#request(s) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/projectsimulator.rb', line 49 def request(s) params = {request: s} requests(params) h = find_request(s) method(h.first[-1]).call(h) end |
#set_device(h) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/projectsimulator.rb', line 59 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
67 68 69 |
# File 'lib/projectsimulator.rb', line 67 def to_sliml() @ed.to_sliml end |
#xml(options = nil) ⇒ Object
71 72 73 |
# File 'lib/projectsimulator.rb', line 71 def xml(=nil) @ed.xml(pretty: true).gsub(' style=\'\'','') end |