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.
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, #expr, #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.
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/phys/units/unit.rb', line 574 def initialize(expr,name,dimval=nil) case name when String @name = name.strip @factor = 1 @dim = {@name=>1} @dim.default = 0 @expr = nil 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.
613 614 615 |
# File 'lib/phys/units/unit.rb', line 613 def dimension_value @dimension_value end |
Class Method Details
Instance Method Details
#dimensionless? ⇒ Boolean
595 596 597 |
# File 'lib/phys/units/unit.rb', line 595 def dimensionless? @dimensionless end |