Class: Trustworthy::Key
- Inherits:
-
Object
- Object
- Trustworthy::Key
- Defined in:
- lib/trustworthy/key.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(x, y) ⇒ Key
constructor
A new instance of Key.
- #to_s ⇒ Object
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
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'lib/trustworthy/key.rb', line 3 def x @x end |
#y ⇒ Object (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_s ⇒ Object
21 22 23 |
# File 'lib/trustworthy/key.rb', line 21 def to_s "#{x.to_s('F')},#{y.to_s('F')}" end |