Module: OpenHAB::CoreExt::Ruby::QuantityTypeConversion
- Included in:
- Integer, OpenHAB::CoreExt::Ruby, Numeric
- Defined in:
- lib/openhab/core_ext/ruby/numeric.rb
Overview
Extend Numeric to create quantity object
Instance Method Summary collapse
-
#|(unit) ⇒ QuantityType
Convert Numeric to a QuantityType.
Instance Method Details
#|(unit) ⇒ QuantityType
Convert Numeric to a QuantityType
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/openhab/core_ext/ruby/numeric.rb', line 153 def |(unit) # rubocop:disable Naming/BinaryOperatorParameterName if unit.respond_to?(:to_str) parsed_unit = org.openhab.core.types.util.UnitUtils.parse_unit(unit.to_str) raise ArgumentError, "Unknown unit #{unit}" unless parsed_unit unit = parsed_unit end return super unless unit.is_a?(javax.measure.Unit) Core::Types::QuantityType.new(to_d.to_java, unit) end |