class Array

Extension to the Array class. These facilitate the creation of RTPConnect strings from an array of values.

Public Instance Methods

encode() click to toggle source

Encodes an RTPConnect string from an array of values. Each value in the array is wrapped with double quotes, before the values are joined with a comma separator.

@return [String] a proper RTPConnect type CSV string

# File lib/rtp-connect/ruby_extensions.rb, line 95
def encode
  wrapped = self.collect{|value| value.wrap}
  return wrapped.join(',')
end
validate_and_process(nr) click to toggle source

Validates the number of elements in an array and converts all elements to strings.

@param [Integer] nr the required number of elements in the array

# File lib/rtp-connect/ruby_extensions.rb, line 105
def validate_and_process(nr)
  raise ArgumentError, "Invalid array length. Expected exactly #{nr} elements, got #{self.length}." unless self.length == nr
  self.collect {|e| e && e.to_s.strip}
end