Method: Quantify::Unit::Base#initialize
- Defined in:
- lib/quantify/unit/base_unit.rb
#initialize(options = nil, &block) ⇒ Base
Create a new Unit::Base instance.
Valid options are: :name => The unit name, e.g. :kilometre
:dimensions => The physical quantity represented
by the unit (e.g. force, mass).
This must be recognised as a member
of the Dimensions.dimensions array
:physical_quantity => Alias for :dimensions
:symbol => The unit symbol, e.g. 'kg'
:factor => The factor which relates the unit
to the SI unit for the same physical
quantity. For example the :factor for
a foot would be 0.3048, since a foot
= 0.3048 m (metre is the SI unit of
length). If no factor is set, it is
assumed to be 1 - which represents
an SI benchmark unit.
:scaling => A scaling factor, used only by NonSI
temperature units
:label => The label used by JScience for the
unit
The physical quantity option is used to locate the corresponding dimensional representation in the Dimensions class. This dimensions attribute is to provide much of the unit functionality
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/quantify/unit/base_unit.rb', line 110 def initialize(=nil,&block) @acts_as_alternative_unit = true @acts_as_equivalent_unit = false self.factor = 1.0 self.symbol = nil self.label = nil self.name = nil self.base_unit = nil self.prefix = nil if .is_a? Hash self.dimensions = [:dimensions] || [:physical_quantity] if [:dimensions] || [:physical_quantity] self.factor = [:factor] if [:factor] self.name = [:name] if [:name] self.symbol = [:symbol] if [:symbol] self.label = [:label] if [:label] end block.call(self) if block_given? valid? end |