Sha256: d477f7ceeaab0bbd0ba35badd9df8e1682b2b83911880414f3064cf1e451399f

Contents?: true

Size: 763 Bytes

Versions: 48

Compression:

Stored size: 763 Bytes

Contents

require_relative 'abstract_command_handler'

class ArrayGetSizeHandler < AbstractCommandHandler
  def initialize
    @required_parameters_count = 1
  end

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

      if command.payload[0].is_a? Array
        return get_size_array(command)
      else
        return get_size(command)
      end
    rescue Exception => e
      return e
    end
  end

  def get_size_array(command)
    array = command.payload[0]
    size = 1
    while array.is_a? Array
      size = size * array.length
      array = array[0]
    end
    size
  end

  def get_size(command)
    command.payload[0].length
  end
end

Version data entries

48 entries across 24 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.5 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.5 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.4 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.4 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.3 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.3 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.2 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.4.2 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.3.0 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.3.0 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.2.0 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/array_get_size_handler.rb
javonet-ruby-sdk-2.2.0 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/array_get_size_handler.rb