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
Instance Attribute Summary
Attributes inherited from Unit
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?, #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.
635 636 637 638 639 640 641 |
# File 'lib/phys/units/unit.rb', line 635 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
631 632 633 |
# File 'lib/phys/units/unit.rb', line 631 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.
653 654 655 |
# File 'lib/phys/units/unit.rb', line 653 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.
646 647 648 |
# File 'lib/phys/units/unit.rb', line 646 def convert_value_to_base_unit(value) value * conversion_factor + @offset end |
#operable? ⇒ Boolean
Returns false
658 659 660 |
# File 'lib/phys/units/unit.rb', line 658 def operable? false end |