class Unitwise::Functional

Functional is an alterative function-based scale for atoms with a non-linear (or non-zero y-intercept) scale. This is most commonly used for temperatures. Known functions for converting to and from special atoms are setup as class methods here.

Attributes

function_name[R]

Public Class Methods

from_2lg(x) click to toggle source
# File lib/unitwise/functional.rb, line 93
def self.from_2lg(x)
  10.0 ** (x / 2.0)
end
from_cel(x) click to toggle source
# File lib/unitwise/functional.rb, line 13
def self.from_cel(x)
  x + 273.15
end
from_degf(x) click to toggle source
# File lib/unitwise/functional.rb, line 21
def self.from_degf(x)
  5.0 / 9.0 * (x + 459.67)
end
from_degre(x) click to toggle source
# File lib/unitwise/functional.rb, line 29
def self.from_degre(x)
  5.0 / 4.0 * (x + 218.52)
end
from_hpC(x) click to toggle source
# File lib/unitwise/functional.rb, line 45
def self.from_hpC(x)
  100.0 ** -x
end
from_hpX(x) click to toggle source
# File lib/unitwise/functional.rb, line 37
def self.from_hpX(x)
  10.0 ** -x
end
from_ld(x) click to toggle source
# File lib/unitwise/functional.rb, line 69
def self.from_ld(x)
  2.0 ** x
end
from_lg(x) click to toggle source
# File lib/unitwise/functional.rb, line 85
def self.from_lg(x)
  10.0 ** x
end
from_ln(x) click to toggle source
# File lib/unitwise/functional.rb, line 77
def self.from_ln(x)
  Math::E ** x
end
from_ph(x) click to toggle source
# File lib/unitwise/functional.rb, line 61
def self.from_ph(x)
  from_hpX(x)
end
from_tan100(x) click to toggle source
# File lib/unitwise/functional.rb, line 53
def self.from_tan100(x)
  atan(x / 100.0)
end
new(value, unit, function_name) click to toggle source

Setup a new functional. @param value [Numeric] The magnitude of the scale @param unit [Unitwise::Unit, String] The unit of the scale @param function_name [String, Symbol] One of the class methods above to be used for conversion

Calls superclass method
# File lib/unitwise/functional.rb, line 104
def initialize(value, unit, function_name)
  @function_name = function_name
  super(value, unit)
end
to_2lg(x) click to toggle source
# File lib/unitwise/functional.rb, line 89
def self.to_2lg(x)
  2.0 * log10(x)
end
to_cel(x) click to toggle source
# File lib/unitwise/functional.rb, line 9
def self.to_cel(x)
  x - 273.15
end
to_degf(x) click to toggle source
# File lib/unitwise/functional.rb, line 17
def self.to_degf(x)
  9.0 * x / 5.0 - 459.67
end
to_degre(x) click to toggle source
# File lib/unitwise/functional.rb, line 25
def self.to_degre(x)
  4.0 * x / 5.0 - 218.52
end
to_hpC(x) click to toggle source
# File lib/unitwise/functional.rb, line 41
def self.to_hpC(x)
  -log(x) / log(100.0)
end
to_hpX(x) click to toggle source
# File lib/unitwise/functional.rb, line 33
def self.to_hpX(x)
  -log10(x)
end
to_ld(x) click to toggle source
# File lib/unitwise/functional.rb, line 65
def self.to_ld(x)
  Math.log(x) / Math.log(2.0)
end
to_lg(x) click to toggle source
# File lib/unitwise/functional.rb, line 81
def self.to_lg(x)
  log10(x)
end
to_ln(x) click to toggle source
# File lib/unitwise/functional.rb, line 73
def self.to_ln(x)
  log(x)
end
to_ph(x) click to toggle source
# File lib/unitwise/functional.rb, line 57
def self.to_ph(x)
  to_hpX(x)
end
to_tan100(x) click to toggle source
# File lib/unitwise/functional.rb, line 49
def self.to_tan100(x)
  100.0 * tan(x)
end

Public Instance Methods

magnitude(scalar = scalar()) click to toggle source

Get the equivalent magnitude on this scale for a scalar value @param scalar [Numeric] A linear scalar value @return [Numeric] The equivalent magnitude on this scale @api public

# File lib/unitwise/functional.rb, line 121
def magnitude(scalar = scalar())
  self.class.send(:"to_#{function_name}", scalar)
end
scalar(magnitude = value) click to toggle source

Get the equivalent scalar value of a magnitude on this scale @param magnitude [Numeric] The magnitude to find the scalar value for @return [Numeric] Equivalent linear scalar value @api public

# File lib/unitwise/functional.rb, line 113
def scalar(magnitude = value)
  self.class.send(:"from_#{function_name}", magnitude)
end