class Phys::OffsetUnit
OffsetUnit
is a class to represent units with offset value. Allows Fahrenheit/Celsius temperature. Unit
operations are not allowed. @example
require 'phys/units' Phys::Quantity[20,:tempC].want(:tempF) #=> Phys::Quantity[68,'tempF'] Phys::Quantity[3,:tempC] + Phys::Quantity[10,:degF] #=> Phys::Quantity[(77/9),"tempC"] Phys::Quantity[3,:tempC] * Phys::Quantity[3,:m] #=> UnitError Phys::Quantity[3,:tempC] ** 2 #=> UnitError # Next examples currently work, but I suggest the use of degC and degF. Phys::Quantity[3,:tempC] + Phys::Quantity[10,:tempF] #=> Phys::Quantity[(77/9),"tempC"] Phys::Quantity[3,:tempC] * 2 #=> Phys::Quantity[6,"tempC"]
Public Class Methods
define(name,unit,offset=nil)
click to toggle source
# File lib/phys/units/unit.rb, line 633 def self.define(name,unit,offset=nil) LIST[name] = self.new(unit,name,offset) end
new(arg,name=nil,offset=nil)
click to toggle source
Calls superclass method
Phys::Unit::new
# File lib/phys/units/unit.rb, line 637 def initialize(arg,name=nil,offset=nil) if offset.nil? raise ArgumentError,"offset is not supplied" end super(arg,name) @offset = offset end
Public Instance Methods
convert_value_from_base_unit(value)
click to toggle source
Convert from a value in base unit to a value in this unit. @param [Numeric] value @return [Numeric]
# File lib/phys/units/unit.rb, line 655 def convert_value_from_base_unit(value) (value - @offset) / conversion_factor end
convert_value_to_base_unit(value)
click to toggle source
Convert from a value in this unit to a value in base unit. @param [Numeric] value @return [Numeric]
# File lib/phys/units/unit.rb, line 648 def convert_value_to_base_unit(value) value * conversion_factor + @offset end
operable?()
click to toggle source
Returns false
# File lib/phys/units/unit.rb, line 660 def operable? false end