Sha256: d7c17d561366989a750177f896c0618f2ee2c89520e0642af297bef1e2b9a1eb

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

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
  end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rserve-client-0.1.8 lib/rserve/rexp/integer.rb
rserve-client-0.1.7 lib/rserve/rexp/integer.rb
rserve-client-0.1.6 lib/rserve/rexp/integer.rb