Class: Measurb::Dimension
- Inherits:
-
Object
- Object
- Measurb::Dimension
- Includes:
- Comparable
- Defined in:
- lib/measurb/dimension.rb
Overview
Base class for defined dimensions to inherit from.
Class Attribute Summary collapse
-
.abbrev ⇒ Object
readonly
Returns the value of attribute abbrev.
-
.dimension_name ⇒ Object
readonly
Returns the value of attribute dimension_name.
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#+(other) ⇒ Measurb::Dimension
Add another dimension.
-
#-(other) ⇒ Measurb::Dimension
Subtract another dimension.
-
#<=>(other) ⇒ -1, ...
Compare with another dimension.
-
#eql?(other) ⇒ Boolean
Check type and value quality with another dimension.
-
#initialize(value, precision = DEFAULT_PRECISION) ⇒ Measurb::Dimension
constructor
Initialize the dimension.
-
#inspect ⇒ String
Get the inspect string.
Constructor Details
#initialize(value, precision = DEFAULT_PRECISION) ⇒ Measurb::Dimension
Initialize the dimension
17 18 19 20 21 |
# File 'lib/measurb/dimension.rb', line 17 def initialize(value, precision = DEFAULT_PRECISION) @precision = precision @original_value = value @value = fix_value(value, precision) end |
Class Attribute Details
.abbrev ⇒ Object (readonly)
Returns the value of attribute abbrev.
9 10 11 |
# File 'lib/measurb/dimension.rb', line 9 def abbrev @abbrev end |
.dimension_name ⇒ Object (readonly)
Returns the value of attribute dimension_name.
9 10 11 |
# File 'lib/measurb/dimension.rb', line 9 def dimension_name @dimension_name end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
6 7 8 |
# File 'lib/measurb/dimension.rb', line 6 def precision @precision end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/measurb/dimension.rb', line 6 def value @value end |
Instance Method Details
#+(other) ⇒ Measurb::Dimension
Add another dimension
27 28 29 |
# File 'lib/measurb/dimension.rb', line 27 def +(other) arithmetic(:+, other) end |
#-(other) ⇒ Measurb::Dimension
Subtract another dimension
35 36 37 |
# File 'lib/measurb/dimension.rb', line 35 def -(other) arithmetic(:-, other) end |
#<=>(other) ⇒ -1, ...
Compare with another dimension
43 44 45 |
# File 'lib/measurb/dimension.rb', line 43 def <=>(other) value <=> to_self(other).value end |
#eql?(other) ⇒ Boolean
Check type and value quality with another dimension
51 52 53 |
# File 'lib/measurb/dimension.rb', line 51 def eql?(other) self.class == other.class && self == other end |
#inspect ⇒ String
Get the inspect string
58 59 60 |
# File 'lib/measurb/dimension.rb', line 58 def inspect "#{value} #{self.class.abbrev || self.class.dimension_name}" end |