Class: Mext::CompressedArray

Inherits:
Array
  • Object
show all
Defined in:
lib/mext/array/compressed_array.rb

Overview

Mext::CompressedArray

is an array in which values are expanded according to the following format: if a value is a 2-place array it is interpreted as: [value, num_of_repetitions]. The array is actually expanded during creation so there is currently no way to retrieve the original format.

Constant Summary

Constants inherited from Array

Array::DOT_OPERATIONS, Array::MINIMUM_STEP, Array::SCALAR_NEW_OPERATIONS, Array::SCALAR_OPERATIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#choose, fill_float

Constructor Details

#initialize(me = []) ⇒ CompressedArray

Mext::CompressedArray.new(me = [])

create a array with a special array whose format accept the following values:

  • single values (go untreated)

  • arrays of two values (interpreted as [value, num_of_repetitions] - num_of_repetitions value is checked to be a Fixnum to expand value for num_of_repetitions (otherwise the array is passed unprocessed)

  • anything else is passed unprocessed



24
25
26
27
# File 'lib/mext/array/compressed_array.rb', line 24

def initialize(me = [])
  new_array = expand(me)
  self.replace(new_array)
end

Class Method Details

.from_yaml(ha) ⇒ Object

from_yaml(hash)

create from a yaml Hash configuration

Raises:

  • (ArgumentError)


36
37
38
39
40
# File 'lib/mext/array/compressed_array.rb', line 36

def from_yaml(ha)
  raise ArgumentError unless ha.kind_of?(Hash) && ha.has_key?('args')
  args = ha['args']
  new(args)
end