Sha256: 08172d7977e9c7a7678835ef8786d771264682f7340b34a18931143d7f1e0cf0

Contents?: true

Size: 1.16 KB

Versions: 46

Compression:

Stored size: 1.16 KB

Contents

require_relative 'abstract_command_handler'

class ArraySetItemHandler < AbstractCommandHandler
  def initialize
    @required_parameters_count = 3
  end

  def process(command)
    begin
      if command.payload.length < @required_parameters_count
        raise ArgumentError.new "Array set item parameters mismatch"
      end
      if command.payload[0].is_a? Array
        set_item_array(command)
      elsif command.payload[0].is_a? Hash
        set_item_hash(command)
      else
        raise ArgumentError.new "Cannot set element of %s" % [command.payload[0]]
      end
      return 0
    rescue Exception => e
      return e
    end
  end

  def set_item_array(command)
    array = command.payload[0]
    value = command.payload[2]
    indexes = if command.payload[1].is_a? Array
                command.payload[1]
              else
                [command.payload[1]]
              end
    indexes[..-2].each { |i|
      array = array[i]
    }
    array[indexes[-1]] = value
  end

  def set_item_hash(command)
    hash = command.payload[0]
    key = command.payload[1]
    value = command.payload[2]
    hash[key] = value
  end

end

Version data entries

46 entries across 23 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/array_set_item_handler.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/core/handler/array_set_item_handler.rb