Sha256: b03470039900aa879fa06ba7e12b66dfe183e8726db3a445453c045c788877a5

Contents?: true

Size: 965 Bytes

Versions: 17

Compression:

Stored size: 965 Bytes

Contents

require 'ms/data/simple'

module Ms
  module Data
    module_function
    
    # Initializes a new transposed data array.
    def new_transposed(unresolved_data)
      Transposed.new(unresolved_data)
    end
    
    # A Transposed data array lazily evaluates it's unresolved data as 
    # a transposed array.  The unresolved data is evaluated 
    # into an array using to_a.
    # 
    #   t = Ms::Data::Transposed.new([[1,4],[2,5],[3,6]])
    # 
    #   t.unresolved_data  # => [[1,4],[2,5],[3,6]]
    #   t.data             # => []
    #   t[0]               # => [1,2,3]
    #   t[1]               # => [4,5,6]
    #   t.data             # => [[1,2,3], [4,5,6]]
    #
    class Transposed < Simple
      
      def [](index)
        resolve.data[index]
      end
      
      def resolved?
        !@data.empty?
      end
      
      def resolve
        @data = @unresolved_data.to_a.transpose unless resolved?
        self
      end
      
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
ms-core-0.0.19 lib/ms/data/transposed.rb
ms-core-0.0.18 lib/ms/data/transposed.rb
ms-core-0.0.17 lib/ms/data/transposed.rb
ms-core-0.0.16 lib/ms/data/transposed.rb
ms-core-0.0.14 lib/ms/data/transposed.rb
ms-core-0.0.13 lib/ms/data/transposed.rb
ms-core-0.0.12 lib/ms/data/transposed.rb
ms-core-0.0.11 lib/ms/data/transposed.rb
ms-core-0.0.10 lib/ms/data/transposed.rb
ms-core-0.0.9 lib/ms/data/transposed.rb
ms-core-0.0.7 lib/ms/data/transposed.rb
ms-core-0.0.6 lib/ms/data/transposed.rb
ms-core-0.0.5 lib/ms/data/transposed.rb
ms-core-0.0.4 lib/ms/data/transposed.rb
ms-core-0.0.2 lib/ms/data/transposed.rb
ms-core-0.0.1 lib/ms/data/transposed.rb
mspire-0.5.0 lib/ms/data/transposed.rb