Class: LegoEv3::Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(user_config = {}) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/connection/connection.rb', line 5

def initialize(user_config = {})
  options = {
    user_config: LegoEv3::default_user_config.merge(user_config)
  }

  OptionParser.new do |opt|
    opt.on('-c, --config PATH', 'Use the provided configuration at PATH.') do |path|
      options[:user_config].merge!(LegoEv3::load_config(path))
    end
  end.parse!
  is_local = `hostname`.strip == options[:user_config]['ssh']['hostname']

  @inner_connection = if is_local
    LegoEv3::LocalConnection.new
  else
    LegoEv3::RemoteConnection.new(
      options[:user_config]['ssh']['host'],
      options[:user_config]['ssh']['username'],
      options[:user_config]['ssh']['password']
    )
  end
end

Instance Method Details

#closeObject



36
37
38
# File 'lib/connection/connection.rb', line 36

def close
  @inner_connection.close
end

#flushObject



32
33
34
# File 'lib/connection/connection.rb', line 32

def flush
  @inner_connection.flush
end

#send(command, &callback) ⇒ Object



28
29
30
# File 'lib/connection/connection.rb', line 28

def send(command, &callback)
  @inner_connection.send(command, &callback)
end