Class: DbClustering::Models::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/models/vector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:) ⇒ Vector

Returns a new instance of Vector.



7
8
9
10
11
12
13
# File 'lib/models/vector.rb', line 7

def initialize(object:)
  if object.is_a?(Hash)
    @hash = object
  else
    @array = object
  end
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/models/vector.rb', line 5

def hash
  @hash
end

Instance Method Details

#array_for_comparison(other_vector) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# 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