Class: Phys::BaseUnit
Overview
BaseUnit is a class to represent units defined by “!” in the data form of GNU units. It includes SI units and dimensionless units such as radian.
Constant Summary
Constants inherited from Unit
Unit::LIST, Unit::PREFIX, Unit::VERSION
Instance Attribute Summary collapse
-
#dimension_value ⇒ Numeric
readonly
Dimension value.
Attributes inherited from Unit
Class Method Summary collapse
Instance Method Summary collapse
- #dimensionless? ⇒ Boolean
-
#initialize(expr, name, dimval = nil) ⇒ BaseUnit
constructor
A new instance of BaseUnit.
Methods inherited from Unit
#*, #**, #+, #+@, #-, #-@, #/, #==, #===, #base_unit, cast, #coerce, #conversion_factor, #convert, #convert_scale, #convert_value_from_base_unit, #convert_value_to_base_unit, #dimension, #factor, find_unit, import_units, #inspect, #inverse, #operable?, parse, prefix_regex, #scalar?, #to_numeric, #to_s, #unit_string
Constructor Details
#initialize(expr, name, dimval = nil) ⇒ BaseUnit
Returns a new instance of BaseUnit.
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/phys/units/unit.rb', line 572 def initialize(expr,name,dimval=nil) case name when String @name = name.strip @factor = 1 @dim = {@name=>1} @dim.default = 0 @expr = expr if String===expr && /!dimensionless/ =~ expr @dimensionless = true end @dimension_value = dimval || 1 else raise ArgumentError,"Second argument must be string: #{name}" end end |
Instance Attribute Details
#dimension_value ⇒ Numeric (readonly)
Dimension value. Returns PI number for pi dimension, otherwise returns one.
611 612 613 |
# File 'lib/phys/units/unit.rb', line 611 def dimension_value @dimension_value end |
Class Method Details
Instance Method Details
#dimensionless? ⇒ Boolean
593 594 595 |
# File 'lib/phys/units/unit.rb', line 593 def dimensionless? @dimensionless end |