Class: EmacsOrgProtocolServer::EmacsClientRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/emacs_org_protocol_server/emacs_client_runner.rb

Defined Under Namespace

Classes: NoParameters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, client = nil, logger = Logger.new(STDERR)) ⇒ EmacsClientRunner

Returns a new instance of EmacsClientRunner.

Raises:



12
13
14
15
16
17
18
19
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 12

def initialize(params={}, client=nil, logger=Logger.new(STDERR))
  raise NoParameters if params.empty?
  self.logger      = logger
  self.client      = client
  self.location    = params['l'].to_s
  self.title       = params['t'].to_s
  self.body        = params['b'].to_s
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 10

def body
  @body
end

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 10

def client
  @client
end

#locationObject

Returns the value of attribute location.



10
11
12
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 10

def location
  @location
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 10

def logger
  @logger
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 10

def title
  @title
end

Instance Method Details

#run!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/emacs_org_protocol_server/emacs_client_runner.rb', line 21

def run!
  emacs_target = URI('org-protocol://capture')
  query_data = {
    template: 'w',
    url: location,
    title: title,
    body: body
  }
  query_string = URI.encode_www_form(query_data).gsub('+','%20')
  emacs_target.query = query_string

  cmd = "#{client} -n '#{emacs_target}'"
  logger.info "emacsclient command: #{cmd}"
  system(cmd)
  return ($? == 0)
end