Class: RinRuby::R_Character

Inherits:
R_DataType show all
Defined in:
lib/rinruby.rb

Constant Summary collapse

ID =
RinRuby_Type_Character

Class Method Summary collapse

Methods inherited from R_DataType

===

Class Method Details

.convertable?(value) ⇒ Boolean

Returns:

  • (Boolean)


758
759
760
761
762
# File 'lib/rinruby.rb', line 758

def convertable?(value)
  value.all?{|x|
    (x == nil) || x.kind_of?(String)
  }
end

.receive(io) ⇒ Object



776
777
778
779
780
781
782
783
# File 'lib/rinruby.rb', line 776

def receive(io)
  length = io.read(4).unpack('l').first
  Array.new(length){|i|
    nchar = io.read(4).unpack('l')[0]
    # negative nchar means NA, and "+ 1" for zero-terminated string
    (nchar >= 0) ? io.read(nchar + 1)[0..-2] : nil
  }
end

.send(value, io) ⇒ Object



763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/rinruby.rb', line 763

def send(value, io)
  # Character format: data_size, data1_bytes, data1, data2_bytes, data2, ...
  io.write([value.size].pack('l'))
  value.each{|x|
    if x then
      bytes = x.to_s.bytes # TODO: taking care of encoding difference
      io.write(([bytes.size] + bytes).pack('lC*')) # .bytes.pack("C*").encoding equals to "ASCII-8BIT"
    else
      io.write([RinRuby_NA_R_Integer].pack('l'))
    end
  }
  value
end