Class: Command

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/utils/command.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/command.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/command.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/utils/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_name, command_type, payload) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 5

def initialize(runtime_name, command_type, payload)
  @runtime_name = runtime_name
  @command_type = command_type
  @payload = payload
end

Class Method Details

.create_array_response(array, runtime_name) ⇒ Object



32
33
34
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 32

def self.create_array_response(array, runtime_name)
  return Command.new(runtime_name, CommandType::ARRAY, array)
end

.create_reference(guid, runtime_name) ⇒ Object



28
29
30
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 28

def self.create_reference(guid, runtime_name)
  return Command.new(runtime_name, CommandType::REFERENCE, [guid])
end

.create_response(response, runtime_name) ⇒ Object



24
25
26
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 24

def self.create_response(response, runtime_name)
  return Command.new(runtime_name, CommandType::VALUE, [response])
end

Instance Method Details

#add_arg_to_payload(argument) ⇒ Object



45
46
47
48
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 45

def add_arg_to_payload(argument)
  merged_payload = payload + [argument]
  return Command.new(@runtime_name, @command_type, merged_payload)
end

#command_typeObject



15
16
17
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 15

def command_type
  @command_type
end

#drop_first_payload_argumentObject



36
37
38
39
40
41
42
43
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 36

def drop_first_payload_argument
  payload_args = []
  payload_args = payload_args + @payload
  if payload_args.length != 0
    payload_args.delete_at(0)
  end
  return Command.new(@runtime_name, @command_type, payload_args)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 63

def eql?(other)
  @is_equal = false
  if self == other
    @is_equal = true
  end
  if other == nil or self.class != other.class
    @is_equal = false
  end
  if self.command_type == other.command_type and self.runtime_name == other.runtime_name
    @is_equal = true
  end
  if payload.length == other.payload.length
    i = 0
    array_item_equal = false
    payload.each { |payload_item|
      if payload_item.eql? other.payload[i]
        array_item_equal = true
      else
        array_item_equal = false
      end
      i += 1
    }
    @is_equal = array_item_equal
  else
    @is_equal = false
  end
  return @is_equal
end

#payloadObject



19
20
21
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 19

def payload
  @payload
end

#prepend_arg_to_payload(current_command) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 50

def prepend_arg_to_payload(current_command)
  if current_command.nil?
    return Command.new(@runtime_name, @command_type, @payload)
  else
    merged_payload = [current_command] + payload
    return Command.new(@runtime_name, @command_type, merged_payload)
  end
end

#runtime_nameObject



11
12
13
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 11

def runtime_name
  @runtime_name
end

#to_stringObject



59
60
61
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 59

def to_string
  'Runtime Library: ' + RuntimeName.get_name(@runtime_name).to_s + ' ' + 'Ruby command type: ' + CommandType.get_name(@command_type).to_s + ' ' + 'with parameters: ' + @payload.to_s
end