Class: Phys::OffsetUnit
Overview
OffsetUnit is a class to represent units with offset value. Allows Fahrenheit/Celsius temperature. Unit operations are not allowed.
Constant Summary
Constants inherited from Unit
Unit::LIST, Unit::PREFIX, Unit::VERSION
Class Method Summary collapse
Instance Method Summary collapse
-
#convert_value_from_base_unit(value) ⇒ Numeric
Convert from a value in base unit to a value in this unit.
-
#convert_value_to_base_unit(value) ⇒ Numeric
Convert from a value in this unit to a value in base unit.
-
#initialize(arg, name = nil, offset = nil) ⇒ OffsetUnit
constructor
A new instance of OffsetUnit.
-
#operable? ⇒ Boolean
Returns false.
Methods inherited from Unit
#*, #**, #+, #+@, #-, #-@, #/, #==, #===, #base_unit, cast, #coerce, #conversion_factor, #convert, #convert_scale, #dimension, #dimension_value, #dimensionless?, #expr, #factor, find_unit, import_units, #inspect, #inverse, parse, prefix_regex, #scalar?, #to_numeric, #to_s, #unit_string
Constructor Details
#initialize(arg, name = nil, offset = nil) ⇒ OffsetUnit
Returns a new instance of OffsetUnit.
637 638 639 640 641 642 643 |
# 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 |
Class Method Details
.define(name, unit, offset = nil) ⇒ Object
633 634 635 |
# File 'lib/phys/units/unit.rb', line 633 def self.define(name,unit,offset=nil) LIST[name] = self.new(unit,name,offset) end |
Instance Method Details
#convert_value_from_base_unit(value) ⇒ Numeric
Convert from a value in base unit to a value in this unit.
655 656 657 |
# 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) ⇒ Numeric
Convert from a value in this unit to a value in base unit.
648 649 650 |
# File 'lib/phys/units/unit.rb', line 648 def convert_value_to_base_unit(value) value * conversion_factor + @offset end |
#operable? ⇒ Boolean
Returns false
660 661 662 |
# File 'lib/phys/units/unit.rb', line 660 def operable? false end |