Class: OpenHAB::Core::Types::PointType
- Inherits:
-
Object
- Object
- OpenHAB::Core::Types::PointType
- Defined in:
- lib/openhab/core/types/point_type.rb
Overview
PointType can be used for items that are dealing with GPS or location awareness functionality.
Instance Attribute Summary collapse
- #altitude ⇒ QuantityType readonly
- #latitude ⇒ QuantityType readonly
- #longitude ⇒ QuantityType readonly
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Check equality with type conversion.
-
#distance_from(other) ⇒ QuantityType
(also: #-)
Calculate the distance in meters from other, ignoring altitude.
-
#eql?(other) ⇒ true, false
Check equality without type conversion.
-
#initialize(latitude, longitude, altitude) ⇒ PointType
constructor
A new instance of PointType.
Constructor Details
#initialize(latitude, longitude, altitude) ⇒ PointType
Returns a new instance of PointType.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/openhab/core/types/point_type.rb', line 18 def initialize(*args) if (2..3).cover?(args.length) args = args.each_with_index.map do |value, index| if value.is_a?(DecimalType) || value.is_a?(StringType) value elsif value.is_a?(QuantityType) unit = (index == 2) ? DSL.unit(SIUnits::METRE.dimension) || SIUnits::METRE : Units::DEGREE_ANGLE DecimalType.new(value.to_unit(unit).to_big_decimal) elsif value.respond_to?(:to_str) StringType.new(value.to_str) elsif value.respond_to?(:to_d) DecimalType.new(value) end end end super(*args) end |
Instance Attribute Details
#altitude ⇒ QuantityType (readonly)
94 95 96 |
# File 'lib/openhab/core/types/point_type.rb', line 94 def altitude QuantityType.new(raw_altitude.to_big_decimal, SIUnits::METRE) end |
#latitude ⇒ QuantityType (readonly)
82 83 84 |
# File 'lib/openhab/core/types/point_type.rb', line 82 def latitude QuantityType.new(raw_latitude.to_big_decimal, Units::DEGREE_ANGLE) end |
#longitude ⇒ QuantityType (readonly)
88 89 90 |
# File 'lib/openhab/core/types/point_type.rb', line 88 def longitude QuantityType.new(raw_longitude.to_big_decimal, Units::DEGREE_ANGLE) end |
Instance Method Details
#==(other) ⇒ true, false
Check equality with type conversion
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/openhab/core/types/point_type.rb', line 56 def ==(other) logger.trace { "(#{self.class}) #{self} == #{other} (#{other.class})" } if other.instance_of?(self.class) equals(other) elsif other.respond_to?(:coerce) return false unless (lhs, rhs = other.coerce(self)) lhs == rhs end end |
#distance_from(other) ⇒ QuantityType Also known as: -
Calculate the distance in meters from other, ignoring altitude.
This algorithm also ignores the oblate spheroid shape of Earth and assumes a perfect sphere, so results are inexact.
105 106 107 108 109 110 |
# File 'lib/openhab/core/types/point_type.rb', line 105 def distance_from(other) logger.trace { "(#{self}).distance_from(#{other} (#{other.class})" } raise TypeError, "#{other.class} can't be coerced into #{self.class}" unless other.is_a?(PointType) QuantityType.new(raw_distance_from(other), SIUnits::METRE) end |
#eql?(other) ⇒ true, false
Check equality without type conversion
42 43 44 45 46 |
# File 'lib/openhab/core/types/point_type.rb', line 42 def eql?(other) return false unless other.instance_of?(self.class) equals(other) end |