Class: Linear1::Standard

Inherits:
Function show all
Defined in:
lib/linear1/standard.rb

Overview

Standard form consisting of the formula `Ax + By = C`

Instance Attribute Summary collapse

Attributes inherited from Function

#power, #slope, #y_intercept

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#direct_variation?, display_num, #execute, #to_direct_variation, #to_function, #x_intercept

Constructor Details

#initialize(a, b, c) ⇒ Standard

Returns a new instance of Standard



14
15
16
17
# File 'lib/linear1/standard.rb', line 14

def initialize a, b, c
  @a, @b, @c = display_num(a), display_num(b), display_num(c)
  super @c / @b / @a, @c / @b
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a



6
7
8
# File 'lib/linear1/standard.rb', line 6

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b



6
7
8
# File 'lib/linear1/standard.rb', line 6

def b
  @b
end

#cObject (readonly)

Returns the value of attribute c



6
7
8
# File 'lib/linear1/standard.rb', line 6

def c
  @c
end

Class Method Details

.try_convert(object) ⇒ Object

Parameters:

  • object (#to_standard, #to_sf)

    object to be converted



7
8
9
10
11
12
13
# File 'lib/linear1/standard.rb', line 7

def self.try_convert(object) # @param object [#to_standard, #to_sf] object to be converted
  case object
    when ->(obj) {obj.respond_to? to_standard} then object.to_standard
    when ->(obj) {obj.respond_to? to_sf} then object.to_sf
  else fail TypeError, "Cannot convert #{object} to Standard" end
  
end

Instance Method Details

#to_point_slopePointSlope Also known as: to_ps

Implicit

Returns:



35
36
37
38
# File 'lib/linear1/standard.rb', line 35

def to_point_slope
  d = rand(100) / 2
  PointSlope.new @c - d, @c + d, slope
end

#to_sString

Returns the equation

Returns:

  • (String)

    the equation



18
19
20
# File 'lib/linear1/standard.rb', line 18

def to_s # @return [String] the equation
  "#{idx a}x + #{idx b}y = #{c}"
end

#to_slope_interceptSlopeIntercept Also known as: to_si

Implicit

Returns:



24
25
26
# File 'lib/linear1/standard.rb', line 24

def to_slope_intercept
  SlopeIntercept.new slope, y_intercept
end