Class: DbClustering::Models::Vector
- Inherits:
-
Object
- Object
- DbClustering::Models::Vector
- Defined in:
- lib/models/vector.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #array_for_comparison(other_vector) ⇒ Object
-
#initialize(object:) ⇒ Vector
constructor
A new instance of Vector.
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
#hash ⇒ Object (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 |