Sha256: 7d60457d29e3135bcd968a0ede3800a68b46803ae55b1778d5452d15b17a27a4

Contents?: true

Size: 1.1 KB

Versions: 48

Compression:

Stored size: 1.1 KB

Contents

require_relative 'abstract_command_handler'

class ArrayGetItemHandler < AbstractCommandHandler
  def initialize
    @required_parameters_count = 2
  end

  def process(command)
    begin
      if command.payload.length < @required_parameters_count
        raise ArgumentError.new "Array get item parameters mismatch"
      end

      if command.payload[0].is_a? Array
        return get_item_array(command)
      elsif command.payload[0].is_a? Hash
        return get_item_hash(command)
      else
        raise ArgumentError.new "Cannot get element from %s" % [command.payload[0]]
      end
    rescue Exception => e
      e
    end
  end

  def get_item_array(command)
    array = command.payload[0]
    indexes = if command.payload[1].is_a? Array
                command.payload[1]
              else
                command.payload[1..]
              end

    if array.is_a? Array
      indexes.each { |i|
        array = array[i]
      }
      array
    end
  end

  def get_item_hash(command)
    hash = command.payload[0]
    key = command.payload[1]
    hash[key]
  end
end

Version data entries

48 entries across 24 versions & 1 rubygems

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