Class: Trustworthy::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/trustworthy/key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Key

Returns a new instance of Key.



16
17
18
19
# File 'lib/trustworthy/key.rb', line 16

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

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



3
4
5
# File 'lib/trustworthy/key.rb', line 3

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



3
4
5
# File 'lib/trustworthy/key.rb', line 3

def y
  @y
end

Class Method Details

.create(slope, intercept) ⇒ Object



5
6
7
8
9
# File 'lib/trustworthy/key.rb', line 5

def self.create(slope, intercept)
  x = Trustworthy::Random.number
  y = slope * x + intercept
  new(x, y)
end

.create_from_string(str) ⇒ Object



11
12
13
14
# File 'lib/trustworthy/key.rb', line 11

def self.create_from_string(str)
  x, y = str.split(',').map { |n| BigDecimal(n) }
  Trustworthy::Key.new(x, y)
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/trustworthy/key.rb', line 21

def to_s
  "#{x.to_s('F')},#{y.to_s('F')}"
end