Class: SecretSharing::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/secret_sharing/point.rb

Overview

This class is used to store a two dimensional point consisting of integers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Create a Point object.

Examples

Point.new(1, 2)
# => #<Point: @x=1 @y=2>

Parameters:

  • x (Integer)

    The x value of the point

  • y (Integer)

    The y value of the point


18
19
20
21
# File 'lib/secret_sharing/point.rb', line 18

def initialize(x, y)
  @x = x
  @y = y
end

Instance Attribute Details

#xInteger (readonly)

Returns x value the point was instantiated with

Returns:

  • (Integer)

    x value the point was instantiated with


5
6
7
# File 'lib/secret_sharing/point.rb', line 5

def x
  @x
end

#yInteger (readonly)

Returns y value the point was instantiated with

Returns:

  • (Integer)

    y value the point was instantiated with


7
8
9
# File 'lib/secret_sharing/point.rb', line 7

def y
  @y
end

Class Method Details

.transpose(points) ⇒ Array

An implementation similar to Array#transpose for Arrays of Points

Examples

point1 = SecretSharing::Point.new(1, 2)
point2 = SecretSharing::Point.new(3, 4)
points = [point1, point2]
Point.transpose(points)
# => [[1, 3], [2, 4]]

Returns:

  • (Array)

    Two Arrays in an Array


34
35
36
37
38
39
40
41
42
43
# File 'lib/secret_sharing/point.rb', line 34

def self.transpose(points)
  x_values = []
  y_values = []

  points.each do |point|
    x_values << point.x
    y_values << point.y
  end
  [x_values, y_values]
end