Module: Mycroft::Helpers
- Included in:
- Messages
- Defined in:
- lib/mycroft/helpers.rb
Instance Method Summary collapse
-
#parse_message(msg) ⇒ Object
Parses a message.
-
#send_message(type, message = nil) ⇒ Object
Sends a message of a specific type.
- #update_dependencies(deps) ⇒ Object
Instance Method Details
#parse_message(msg) ⇒ Object
Parses a message
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mycroft/helpers.rb', line 5 def (msg) msg = msg.to_s re = /([A-Z_]+) ({.*})$/ msg_split = re.match(msg) if msg_split.nil? re = /^([A-Z_]+)$/ msg_split = re.match(msg) raise "Error: Malformed Message" if not msg_split type = msg_split[1] data = {} else type = msg_split[1] data = JSON.parse(msg_split[2]) end {type: type, data: data} end |
#send_message(type, message = nil) ⇒ Object
Sends a message of a specific type
23 24 25 26 27 28 29 |
# File 'lib/mycroft/helpers.rb', line 23 def (type, =nil) = .nil? ? = '' : .to_json body = type + ' ' + body.strip! length = body.bytesize @client.write("#{length}\n#{body}") end |
#update_dependencies(deps) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/mycroft/helpers.rb', line 31 def update_dependencies(deps) deps.each do |capability, instance| @dependencies[capability] ||= {} instance.each do |app_id, status| @dependencies[capability][app_id] = status end end end |