Class: NotepadqqApi

Inherits:
Object
  • Object
show all
Defined in:
lib/notepadqq_api.rb,
lib/notepadqq_api/stubs.rb,
lib/notepadqq_api/message_channel.rb,
lib/notepadqq_api/message_interpreter.rb

Defined Under Namespace

Modules: Stubs Classes: MessageChannel, MessageInterpreter

Constant Summary collapse

NQQ_STUB_ID =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socketPath = ARGV[0], extensionId = ARGV[1]) ⇒ NotepadqqApi

Returns a new instance of NotepadqqApi.



11
12
13
14
15
16
17
# File 'lib/notepadqq_api.rb', line 11

def initialize(socketPath = ARGV[0], extensionId = ARGV[1])
  @socketPath = socketPath
  @extensionId = extensionId
  
  @messageChannel = MessageChannel.new(@socketPath)
  @messageInterpreter = MessageInterpreter.new(@messageChannel)
end

Instance Attribute Details

#extensionIdObject (readonly)

Returns the value of attribute extensionId.



9
10
11
# File 'lib/notepadqq_api.rb', line 9

def extensionId
  @extensionId
end

Instance Method Details

#notepadqqObject

Returns an instance of Notepadqq



33
34
35
36
# File 'lib/notepadqq_api.rb', line 33

def notepadqq
  @nqq ||= Stubs::Notepadqq.new(@messageInterpreter, NQQ_STUB_ID);
  return @nqq
end

#runEventLoopObject

Start reading messages and calling event handlers



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/notepadqq_api.rb', line 20

def runEventLoop
  yield
  
  while true do
    messages = @messageChannel.getMessages
    messages.each do |msg|
      @messageInterpreter.processMessage(msg)
    end
  end
  
end