Class: SiriProxy::Plugin

Inherits:
Cora::Plugin
  • Object
show all
Defined in:
lib/siriproxy/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Plugin

Returns a new instance of Plugin.



6
7
8
# File 'lib/siriproxy/plugin.rb', line 6

def initialize(config)

end

Instance Attribute Details

#plugin_nameObject

Returns the value of attribute plugin_name.



4
5
6
# File 'lib/siriproxy/plugin.rb', line 4

def plugin_name
  @plugin_name
end

Class Method Details

.filter(class_names, options = {}, &block) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/siriproxy/plugin.rb', line 42

def filter(class_names, options={}, &block)
  [class_names].flatten.each do |class_name|
    filters[class_name] = {
      direction: (options[:direction] ||= :both),
      block: block
    }
  end
end

.filtersObject



51
52
53
# File 'lib/siriproxy/plugin.rb', line 51

def filters
  @filters ||= {}
end

Instance Method Details

#filtersObject



56
57
58
# File 'lib/siriproxy/plugin.rb', line 56

def filters
  self.class.filters
end

#last_ref_idObject



26
27
28
# File 'lib/siriproxy/plugin.rb', line 26

def last_ref_id
  self.manager.iphone_conn.last_ref_id
end

#process_filters(object, direction) ⇒ Object

direction should be :from_iphone, or :from_guzzoni



31
32
33
34
35
36
37
38
39
# File 'lib/siriproxy/plugin.rb', line 31

def process_filters(object, direction)
  return nil if object == nil
  f = filters[object["class"]]
  if(f != nil && (f[:direction] == :both || f[:direction] == direction))
    object = instance_exec(object, &f[:block])
  end

  object
end

#request_completedObject



10
11
12
# File 'lib/siriproxy/plugin.rb', line 10

def request_completed
  self.manager.send_request_complete_to_iphone
end

#send_object(object, options = {}) ⇒ Object

use send_object(object, target: :guzzoni) to send to guzzoni



15
16
17
18
19
20
21
22
23
24
# File 'lib/siriproxy/plugin.rb', line 15

def send_object(object, options={})
  (object = object.to_hash) rescue nil #convert SiriObjects to a hash
  options[:target] = options[:target] ||= :iphone

  if(options[:target] == :iphone)
    self.manager.guzzoni_conn.inject_object_to_output_stream(object)
	elsif(options[:target] == :guzzoni)
	  self.manager.iphone_conn.inject_object_to_output_stream(object)
	end
end

#to_sObject



60
61
62
# File 'lib/siriproxy/plugin.rb', line 60

def to_s
  self.plugin_name
end