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



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



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

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



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