class Charty::VectorAdapters::VectorAdapter

Public Class Methods

new(data, index: nil) click to toggle source
# File lib/charty/vector_adapters/vector_adapter.rb, line 13
def initialize(data, index: nil)
  data = check_data(data)
  @data = reduce_nested_vector(data)
  self.index = index || RangeIndex.new(0 ... length)
end
supported?(data) click to toggle source
# File lib/charty/vector_adapters/vector_adapter.rb, line 9
def self.supported?(data)
  data.is_a?(Vector)
end

Public Instance Methods

compare_data_equality(other) click to toggle source
# File lib/charty/vector_adapters/vector_adapter.rb, line 39
def compare_data_equality(other)
  if other.is_a?(self.class)
    other = reduce_nested_vector(other.data).adapter
  end
  if other.is_a?(self.class)
    @data.adapter.data == other.data
  elsif @data.adapter.respond_to?(:compare_data_equality)
    @data.adapter.compare_data_equality(other)
  elsif other.respond_to?(:compare_data_equality)
    other.compare_data_equality(@data.adapter)
  else
    @data.adapter.to_a == other.to_a
  end
end

Private Instance Methods

reduce_nested_vector(vector) click to toggle source
# File lib/charty/vector_adapters/vector_adapter.rb, line 54
        def reduce_nested_vector(vector)
  while vector.adapter.is_a?(self.class)
    vector = vector.adapter.data
  end
  vector
end