Sha256: 2104cc5b032f69fbb39e21c12a3a938749799804ec45159ee1ad3eeab1a97c1d

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

module Rserve
  class REXP
    class Integer < REXP::Vector
      public_class_method :new
      attr_reader :payload
      NA = -2147483648;
      def initialize(data, attrs=nil)
        @payload=case data
      when Integer
        [data]
      when Numeric
        [data.to_i]
      when Array
        data
      else
        raise ArgumentError, "Should be Numeric or Array"
      end
      super(attrs)
    end
    def length
      payload.length
    end
    def integer?
      true
    end
    def numeric?
      true
    end
    def as_integers
      @payload
    end
    def as_doubles
      @payload.map(&:to_f)
    end
    def as_strings
      @payload.map(&:to_s)
    end

    def na?(value=nil)
      return value == NA unless value.nil?
      @payload.map {|v| v==NA}
    end
    def to_debug_string
      t=super
      t << "{"  << @payload.map(&:to_s).join(",") << "}"
    end
    def to_ruby_internal
      if dim
        if dim.size==2
          as_matrix
        else
          as_nested_array
        end
      else
        super
      end
    end
    
  end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rserve-client-0.2.4 lib/rserve/rexp/integer.rb
rserve-client-0.2.3 lib/rserve/rexp/integer.rb
rserve-client-0.2.2 lib/rserve/rexp/integer.rb
rserve-client-0.2.1 lib/rserve/rexp/integer.rb
rserve-client-0.2.0 lib/rserve/rexp/integer.rb
rserve-client-0.1.9 lib/rserve/rexp/integer.rb