Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rtp-connect/ruby_extensions.rb
Overview
Extension to the Array class. These facilitate the creation of RTPConnect strings from an array of values.
Instance Method Summary collapse
-
#encode ⇒ String
Encodes an RTPConnect string from an array of values.
-
#validate_and_process(nr) ⇒ Object
Validates the number of elements in an array and converts all elements to strings.
Instance Method Details
#encode ⇒ String
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.
95 96 97 98 |
# 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) ⇒ Object
Validates the number of elements in an array and converts all elements to strings.
105 106 107 108 |
# 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 |