Class: Charty::VectorAdapters::VectorAdapter

Inherits:
BaseAdapter
  • Object
show all
Extended by:
Forwardable
Includes:
IndexSupport, NameSupport, Enumerable
Defined in:
lib/charty/vector_adapters/vector_adapter.rb

Instance Attribute Summary

Attributes included from IndexSupport

#index

Attributes included from NameSupport

#name

Attributes inherited from BaseAdapter

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IndexSupport

#[], #[]=

Methods inherited from BaseAdapter

#==, adapter_name, #inverse_log_scale, #log_scale, #mean, #percentile, #stdev, #values_at, #where_in_array

Constructor Details

#initialize(data, index: nil) ⇒ VectorAdapter

Returns a new instance of VectorAdapter.



13
14
15
16
17
# 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

Class Method Details

.supported?(data) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/charty/vector_adapters/vector_adapter.rb', line 9

def self.supported?(data)
  data.is_a?(Vector)
end

Instance Method Details

#compare_data_equality(other) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/charty/vector_adapters/vector_adapter.rb', line 40

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