Class: OpenHAB::Core::Events::Source::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/events/source.rb

Overview

Represents a single component in the event source delegation chain.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actorString (readonly)

The actor (user, device, etc.) that sent the event.

Returns:

  • (String)


222
223
224
# File 'lib/openhab/core/events/source.rb', line 222

def actor
  @actor
end

#bundleString (readonly)

The bundle (module, app, etc.) that sent the event.

Returns:

  • (String)


218
219
220
# File 'lib/openhab/core/events/source.rb', line 218

def bundle
  @bundle
end

Class Method Details

.build(bundle, actor = nil) ⇒ Component

Build a OpenHAB::Core::Events::Source::Component from the specified bundle and actor.

Parameters:

  • bundle (String)

    The bundle (module, app, etc.) that sent the event.

  • actor (String, nil) (defaults to: nil)

    The actor (user, device, etc.) that sent the event.

Returns:



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/openhab/core/events/source.rb', line 242

def build(bundle, actor = nil)
  if AbstractEvent.respond_to?(:build_source)
    # a bit round-about, but is necessary for argument validation
    # and escaping
    # Only present in openHAB 5.1+
    begin
      parse(AbstractEvent.build_source(bundle, actor))
    rescue java.lang.IllegalArgumentException => e
      raise ArgumentError, e.message
    end
  else
    new(bundle, actor)
  end
end

.parse(component) ⇒ Component

Parse a OpenHAB::Core::Events::Source::Component from its string representation.

Parameters:

Returns:



231
232
233
# File 'lib/openhab/core/events/source.rb', line 231

def parse(component)
  new(*component.split("$", 2))
end

Instance Method Details

#!=(other) ⇒ true, false

Returns:

  • (true, false)


277
278
279
# File 'lib/openhab/core/events/source.rb', line 277

def !=(other)
  !(self == other) # rubocop:disable Style/InverseMethods
end

#<=>(other) ⇒ Integer?

Returns:



282
283
284
285
286
287
# File 'lib/openhab/core/events/source.rb', line 282

def <=>(other)
  return 0 if self == other
  return nil unless other.respond_to?(:to_str)

  to_s <=> other.to_str
end

#==(other) ⇒ true, false

Returns:

  • (true, false)


269
270
271
272
273
274
# File 'lib/openhab/core/events/source.rb', line 269

def ==(other)
  return bundle == other.bundle && actor == other.actor if other.is_a?(Component)
  return to_s == other.to_str if other.respond_to?(:to_str)

  false
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


289
290
291
# File 'lib/openhab/core/events/source.rb', line 289

def eql?(other)
  other.is_a?(Component) && bundle == other.bundle && actor == other.actor
end

#hashInteger

Returns:



294
295
296
# File 'lib/openhab/core/events/source.rb', line 294

def hash
  [bundle, actor].hash
end

#to_sString Also known as: to_str

Returns:

  • (String)


259
260
261
262
263
264
265
# File 'lib/openhab/core/events/source.rb', line 259

def to_s
  if actor
    "#{bundle}$#{actor}"
  else
    bundle
  end
end