Module: Measurb
- Defined in:
- lib/measurb.rb,
lib/measurb/config.rb,
lib/measurb/version.rb,
lib/measurb/core_ext.rb,
lib/measurb/dimension.rb,
lib/measurb/dimension_builder.rb
Overview
Main module
Defined Under Namespace
Modules: CoreExt Classes: Config, Dimension, DimensionBuilder, DuplicateDimensionError
Constant Summary collapse
- DEFAULT_PRECISION =
3
- VERSION =
'0.0.2'
Class Method Summary collapse
- .configure {|config| ... } ⇒ nil
-
.define(name, options = {}, &block) ⇒ Measurb::Dimension
Define a new dimension class and helper singleton method.
-
.dimension_exists?(name) ⇒ Boolean
Check if the dimension already exists.
Class Method Details
.configure {|config| ... } ⇒ nil
63 64 65 |
# File 'lib/measurb.rb', line 63 def configure yield config end |
.define(name, options = {}, &block) ⇒ Measurb::Dimension
Define a new dimension class and helper singleton method
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/measurb.rb', line 33 def define(name, = {}, &block) # Check if the dimension has already been defined if dimension_exists?(name) raise DuplicateDimensionError, "Already defined dimension class `#{DimensionBuilder.get_dimension_class_name(name)}`" end # Create the dimension builder builder = DimensionBuilder.new(name, , &block) # Add the class constant and helper method to the module const_set(builder.dimension_class_name, builder.dimension_class) add_dimension_method(name, builder.dimension_class_name) # Add the helper methods to 'Numeric' CoreExt.add_numeric_dimension(name, builder.dimension_class_name, builder.dimension_class.abbrev) builder.dimension_class end |
.dimension_exists?(name) ⇒ Boolean
Check if the dimension already exists
79 80 81 |
# File 'lib/measurb.rb', line 79 def dimension_exists?(name) const_defined?(DimensionBuilder.get_dimension_class_name(name)) end |