Class: MeshChat::Instance

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Instance

Returns a new instance of Instance.



21
22
23
24
# File 'lib/meshchat/instance.rb', line 21

def initialize(options = {})
  self.client_name = options[:client_name] || MeshChat::NAME
  self.client_version = options[:client_version] || MeshChat::VERSION
end

Instance Attribute Details

#client_nameObject

Returns the value of attribute client_name.



3
4
5
# File 'lib/meshchat/instance.rb', line 3

def client_name
  @client_name
end

#client_versionObject

Returns the value of attribute client_version.



3
4
5
# File 'lib/meshchat/instance.rb', line 3

def client_version
  @client_version
end

#displayObject

Returns the value of attribute display.



3
4
5
# File 'lib/meshchat/instance.rb', line 3

def display
  @display
end

Class Method Details

.instanceObject



16
17
18
# File 'lib/meshchat/instance.rb', line 16

def instance
  @instance
end

.start(options) ⇒ Object



9
10
11
12
13
14
# File 'lib/meshchat/instance.rb', line 9

def start(options)
  # calling instance to get things going
  @instance = new(options)
  @instance.start_input_device(options[:input])
  @instance.start_ui(options[:display], options[:on_display_start])
end

Instance Method Details

#start_input_device(klass) ⇒ Object



35
36
37
38
# File 'lib/meshchat/instance.rb', line 35

def start_input_device(klass)
  # The CLI is a singleton that takes a method of input
  MeshChat::CLI.create(klass)
end

#start_ui(klass, on_display_start) ⇒ Object

Parameters:

  • klass (Class)

    should be something that implements Display::Base

  • proc (Proc)

    what to do when starting the UI



28
29
30
31
32
33
# File 'lib/meshchat/instance.rb', line 28

def start_ui(klass, on_display_start)
  self.display = Display::Manager.new(klass)
  display.start do
    on_display_start.call if on_display_start
  end
end