Class: GeneValidator::Pair

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/genevalidator/clusterization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



3
4
5
# File 'lib/genevalidator/clusterization.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



3
4
5
# File 'lib/genevalidator/clusterization.rb', line 3

def y
  @y
end

Instance Method Details

#*(other) ⇒ Object

Overload ‘*’ operator This will modify the current object



30
31
32
33
# File 'lib/genevalidator/clusterization.rb', line 30

def *(other)
  self.x *= other
  self.y *= other
end

#+(other) ⇒ Object

Overload ‘+’ operator This will modify the current object



22
23
24
25
# File 'lib/genevalidator/clusterization.rb', line 22

def +(other)
  self.x += other.x
  self.y += other.y
end

#-(other) ⇒ Object

Overload ‘-’ operator Returns the euclidian distane between two pairs



9
10
11
12
13
# File 'lib/genevalidator/clusterization.rb', line 9

def -(other)
  xx = other.x
  yy = other.y
  Math.sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy))
end

#/(other) ⇒ Object

Overload ‘/’ operator This will modify the current object



38
39
40
41
# File 'lib/genevalidator/clusterization.rb', line 38

def /(other)
  self.x /= other.to_f
  self.y /= other.to_f
end

#==(other) ⇒ Object

Overload quality operator Returns true if the pairs are equal, false otherwise



46
47
48
# File 'lib/genevalidator/clusterization.rb', line 46

def ==(other)
  other.x == x && other.y == y ? true : false
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/genevalidator/clusterization.rb', line 50

def eql?(other)
  self == other
end

#hashObject



54
55
56
# File 'lib/genevalidator/clusterization.rb', line 54

def hash
  [self.x, self.y].hash
end


15
16
17
# File 'lib/genevalidator/clusterization.rb', line 15

def print
  warn "Cluster: #{x} #{y}"
end