Class: Measurb::DimensionBuilder
- Inherits:
-
Object
- Object
- Measurb::DimensionBuilder
- Defined in:
- lib/measurb/dimension_builder.rb
Overview
Factory class for building new dimension classes
Defined Under Namespace
Classes: ValueProxy
Instance Attribute Summary collapse
-
#dimension_class ⇒ Measurb::Dimension
readonly
Get the dimension class, creating it if it’s not available.
-
#dimension_class_name ⇒ Object
readonly
Returns the value of attribute dimension_class_name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.get_dimension_class_name(name) ⇒ String
Get an appropriate class name for a dimension name.
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ DimensionBuilder
constructor
Initialize the builder.
-
#method_missing(name, *args, &block) ⇒ Object
Use to build conversion methods to other dimensions.
Constructor Details
#initialize(name, options = {}, &block) ⇒ DimensionBuilder
Initialize the builder
20 21 22 23 24 25 |
# File 'lib/measurb/dimension_builder.rb', line 20 def initialize(name, = {}, &block) @name = name @def_block = block @options = @dimension_class_name = self.class.get_dimension_class_name(name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Use to build conversion methods to other dimensions
36 37 38 |
# File 'lib/measurb/dimension_builder.rb', line 36 def method_missing(name, *args, &block) build_default_conversion(name, args.first) end |
Instance Attribute Details
#dimension_class ⇒ Measurb::Dimension (readonly)
Get the dimension class, creating it if it’s not available
30 31 32 33 |
# File 'lib/measurb/dimension_builder.rb', line 30 def dimension_class build_dimension_class unless defined?(@dimension_class) @dimension_class end |
#dimension_class_name ⇒ Object (readonly)
Returns the value of attribute dimension_class_name.
4 5 6 |
# File 'lib/measurb/dimension_builder.rb', line 4 def dimension_class_name @dimension_class_name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/measurb/dimension_builder.rb', line 4 def value @value end |
Class Method Details
.get_dimension_class_name(name) ⇒ String
Get an appropriate class name for a dimension name
10 11 12 |
# File 'lib/measurb/dimension_builder.rb', line 10 def self.get_dimension_class_name(name) name.to_s.split('_').map(&:capitalize).join end |