class DbClustering::Models::Vector

Attributes

hash[R]

Public Class Methods

new(object:) click to toggle source
# File lib/models/vector.rb, line 7
def initialize(object:)
  if object.is_a?(Hash)
    @hash = object
  else
    @array = object
  end
end

Public Instance Methods

array_for_comparison(other_vector) click to toggle source
# File lib/models/vector.rb, line 15
def array_for_comparison(other_vector)
  if @hash
    if other_vector
      shared_keys = @hash.keys & other_vector.hash.keys
      @hash.select{ |k,v| !k.nil? && shared_keys.include?(k) }.sort.map{ |arr| arr.last }
    else
      @hash.values
    end
  else
    @array
  end
end