Class: Linear::SlopeIntercept

Inherits:
Function
  • Object
show all
Defined in:
lib/linear/slope_intercept.rb

Direct Known Subclasses

DirectVariation

Instance Attribute Summary

Attributes inherited from Function

#power, #slope, #y_intercept

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#direct_variation?, #execute, #to_direct_variation, #to_slope_intercept, #x_intercept

Constructor Details

#initialize(slope, y_intercept) ⇒ SlopeIntercept

Returns a new instance of SlopeIntercept


15
16
17
# File 'lib/linear/slope_intercept.rb', line 15

def initialize(slope, y_intercept)
  super
end

Class Method Details

.find(index1, array = ARGV) ⇒ Object


4
5
6
7
8
9
10
11
# File 'lib/linear/slope_intercept.rb', line 4

def self.find(index1, array=ARGV)
  i = 0
  until i == 2
    raise ArgumentError, "array[#{index1 + i}] must be a number" unless (array[index1 + i].to_i.to_s == array[index1 + i] || array[index1 + i].to_f.to_s == array[index1 + i])
    i += 1
  end
  return new array[index1+0].to_f, array[index1+1].to_f
end

Instance Method Details

#to_sObject


12
13
14
# File 'lib/linear/slope_intercept.rb', line 12

def to_s
  return super.sub "f(x)", "y"
end

#to_standardObject


18
19
20
21
# File 'lib/linear/slope_intercept.rb', line 18

def to_standard
  require "linear/standard"
  Standard.new slope, -1, -y_intercept
end