Class: Rserve::REXP::String

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

Constant Summary collapse

NA =
["NA", "\xFF"]

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, #to_ruby_internal, #vector?

Methods inherited from Rserve::REXP

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

Constructor Details

#initialize(data, attrs = nil) ⇒ String

Returns a new instance of String.



6
7
8
9
10
11
12
13
14
# File 'lib/rserve/rexp/string.rb', line 6

def initialize(data, attrs=nil)
  @payload=case data
  when Array
    data.map {|v| v.to_s}
  else
    [data.to_s]
  end
  super(attrs)
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'lib/rserve/rexp/string.rb', line 4

def payload
  @payload
end

Instance Method Details

#as_stringsObject



21
22
23
# File 'lib/rserve/rexp/string.rb', line 21

def as_strings
  @payload
end

#lengthObject



15
16
17
# File 'lib/rserve/rexp/string.rb', line 15

def length
  payload.length
end

#na?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/rserve/rexp/string.rb', line 25

def na?(value=nil)
  if value.nil?
    @payload.map {|v| NA.include? v}
  else
    NA.include? value
  end
end

#string?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rserve/rexp/string.rb', line 18

def string?
  true
end

#to_debug_stringObject



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

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