Class: OpenHAB::Core::Types::StringType

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/types/string_type.rb

Overview

StringType represents a String as a Type and a Command.

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Integer?

Comparison

Parameters:

  • other (StringType, String)

    object to compare to

Returns:

  • (Integer, nil)

    -1, 0, +1 depending on whether other is less than, equal to, or greater than self

    nil is returned if the two values are incomparable.



43
44
45
46
47
48
49
50
51
52
# File 'lib/openhab/core/types/string_type.rb', line 43

def <=>(other)
  logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
  if other.respond_to?(:to_str)
    to_str <=> other.to_str
  elsif other.respond_to?(:coerce)
    return nil unless (lhs, rhs = other.coerce(self))

    lhs <=> rhs
  end
end

#coerce(other) ⇒ [StringType, StringType]?

Type Coercion

Coerce object to a StringType

Parameters:

  • other (String)

    object to coerce to a DateTimeType

Returns:



64
65
66
67
# File 'lib/openhab/core/types/string_type.rb', line 64

def coerce(other)
  logger.trace("Coercing #{self} as a request from #{other.class}")
  [other.to_str, self] if other.respond_to?(:to_str)
end

#eql?(other) ⇒ true, false

Check equality without type conversion

Returns:

  • (true, false)

    if the same value is represented, without type conversion



26
27
28
29
30
# File 'lib/openhab/core/types/string_type.rb', line 26

def eql?(other)
  return false unless other.instance_of?(self.class)

  to_s == other.to_s
end