Module: UnitMeasurements
- Defined in:
- lib/unit_measurements/base.rb,
lib/unit_measurements/math.rb,
lib/unit_measurements/unit.rb,
lib/unit_measurements/cache.rb,
lib/unit_measurements/parser.rb,
lib/unit_measurements/version.rb,
lib/unit_measurements/formatter.rb,
lib/unit_measurements/arithmetic.rb,
lib/unit_measurements/comparison.rb,
lib/unit_measurements/conversion.rb,
lib/unit_measurements/normalizer.rb,
lib/unit_measurements/unit_group.rb,
lib/unit_measurements/measurement.rb,
lib/unit_measurements/configuration.rb,
lib/unit_measurements/errors/unit_error.rb,
lib/unit_measurements/errors/parse_error.rb,
lib/unit_measurements/unit_group_builder.rb,
lib/unit_measurements/extras/numeric_methods.rb,
lib/unit_measurements/errors/blank_unit_error.rb,
lib/unit_measurements/extras/conversion_methods.rb,
lib/unit_measurements/errors/blank_quantity_error.rb,
lib/unit_measurements/errors/unit_already_defined_error.rb,
lib/unit_measurements/errors/missing_primitive_unit_error.rb,
lib/unit_measurements/errors/primitive_unit_already_set_error.rb
Overview
-*- warn_indent: true -*-
Defined Under Namespace
Modules: Arithmetic, Comparison, Conversion, ConversionMethods, Formatter, Math, NumericMethods Classes: BaseError, BlankQuantityError, BlankUnitError, Cache, Configuration, Measurement, MissingPrimitiveUnitError, Normalizer, ParseError, Parser, PrimitiveUnitAlreadySetError, Unit, UnitAlreadyDefinedError, UnitError, UnitGroup, UnitGroupBuilder
Constant Summary collapse
- VERSION =
Current stable version.
"5.17.0"
Class Attribute Summary collapse
-
.configuration ⇒ Configuration
Returns an instance of
Configuration
with the values of desired configurable options of unit_measurements.
Class Method Summary collapse
-
.build {|builder| ... } ⇒ Class
Creates a new unit group based on the provided
block
of instructions. -
.configure {|configuration| ... } ⇒ Object
Configures options of the UnitMeasurements module using a block.
-
.reset ⇒ Configuration
Reset the configuration to its default state.
Class Attribute Details
.configuration ⇒ Configuration
Returns an instance of Configuration
with the values of desired configurable options of unit_measurements. If instance is not present, it initializes a new instance of Configuration.
112 113 114 |
# File 'lib/unit_measurements/base.rb', line 112 def configuration @configuration ||= Configuration.new end |
Class Method Details
.build {|builder| ... } ⇒ Class
Creates a new unit group based on the provided block
of instructions.
The build
method allows you to define and create a custom unit group with units and their conversions. It takes a block of instructions as an argument, which is evaluated by an instance of UnitGroupBuilder
.
Within the block
, you can use various methods provided by UnitGroupBuilder
to define units, group them into unit system, and set primitive unit of the unit group. These methods include primitive
, system
, si_unit
, and unit
.
The resulting unit group is encapsulated in a new subclass of Measurement
. This subclass will have access to the defined units and their conversions through the unit_group
class attribute.
This method provides a powerful way to create specialized unit groups tailored to specific measurement domains.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/unit_measurements/base.rb', line 91 def build(&block) builder = UnitGroupBuilder.new builder.instance_eval(&block) Class.new(Measurement) do class << self attr_reader :unit_group end @unit_group = builder.build end end |
.configure {|configuration| ... } ⇒ Object
Configures options of the UnitMeasurements module using a block. It yields the current Configuration
instance for updating default values of options by new values specified within a block.
147 148 149 |
# File 'lib/unit_measurements/base.rb', line 147 def configure yield configuration end |
.reset ⇒ Configuration
Reset the configuration to its default state.
125 126 127 |
# File 'lib/unit_measurements/base.rb', line 125 def reset @configuration = Configuration.new end |