Class: Rserve::REXP::Integer

Inherits:
Vector show all
Defined in:
lib/rserve/rexp/integer.rb

Direct Known Subclasses

Factor

Constant Summary collapse

NA =
-2147483648;

Constants inherited from Rserve::REXP

MaxDebugItems, MismatchError

Instance Attribute Summary collapse

Attributes inherited from Rserve::REXP

#attr

Instance Method Summary collapse

Methods inherited from Vector

#==, #to_a, #vector?

Methods inherited from Rserve::REXP

#as_bytes, #as_double, #as_double_matrix, #as_factor, #as_float, #as_floats, #as_integer, #as_list, #as_matrix, #as_nested_array, #as_string, #complex?, create_data_frame, #dim, #environment?, #expression?, #factor?, #get_attribute, #has_attribute?, #inherits?, #language?, #list?, #logical?, #null?, #pair_list?, #raw?, #recursive?, #reference?, #split_array, #string?, #symbol?, #to_f, #to_i, #to_ruby, #vector?

Constructor Details

#initialize(data, attrs = nil) ⇒ Integer

Returns a new instance of Integer.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rserve/rexp/integer.rb', line 7

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

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/rserve/rexp/integer.rb', line 5

def payload
  @payload
end

Instance Method Details

#as_doublesObject



32
33
34
# File 'lib/rserve/rexp/integer.rb', line 32

def as_doubles
  @payload.map(&:to_f)
end

#as_integersObject



29
30
31
# File 'lib/rserve/rexp/integer.rb', line 29

def as_integers
  @payload
end

#as_stringsObject



35
36
37
# File 'lib/rserve/rexp/integer.rb', line 35

def as_strings
  @payload.map(&:to_s)
end

#integer?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rserve/rexp/integer.rb', line 23

def integer?
  true
end

#lengthObject



20
21
22
# File 'lib/rserve/rexp/integer.rb', line 20

def length
  payload.length
end

#na?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/rserve/rexp/integer.rb', line 39

def na?(value=nil)
  return value == NA unless value.nil?
  @payload.map {|v| v==NA}
end

#numeric?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rserve/rexp/integer.rb', line 26

def numeric?
  true
end

#to_debug_stringObject



43
44
45
46
# File 'lib/rserve/rexp/integer.rb', line 43

def to_debug_string
  t=super
  t << "{"  << @payload.map(&:to_s).join(",") << "}"
end

#to_ruby_internalObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rserve/rexp/integer.rb', line 47

def to_ruby_internal
  if dim
    if dim.size==2
      as_matrix
    else
      as_nested_array
    end
  else
    super
  end
end