Class: Rri::RConverters::ArrayConverter
- Inherits:
-
Object
- Object
- Rri::RConverters::ArrayConverter
- Defined in:
- lib/rri/r_converters/array_converter.rb
Overview
Converter for ruby Arrays
Instance Method Summary collapse
-
#convert(obj) ⇒ Array
Convert ruby object to R format.
Instance Method Details
#convert(obj) ⇒ Array
Convert ruby object to R format
If the ruby object is an Array, converts it into an R object.
Does not deal with empty arrays.
Depending on what type of content the ruby array has, different things happen:
- if all elements are doubles, convert to vector of doubles
- if all elements are integers, convert to vector of integers
- if all elements are strings, convert to vector of strings
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rri/r_converters/array_converter.rb', line 23 def convert(obj) if obj.kind_of? Array and obj.size > 0 if is_all_same_type?(obj) o = obj[0] return [true, create_integer_vector(obj)] if o.kind_of? Integer return [true, create_double_vector(obj)] if o.kind_of? Float return [true, create_string_vector(obj)] if o.kind_of? String [false, nil] end else [false, nil] end end |