Class: OpenHAB::Core::Things::Thing::ChannelsArray

Inherits:
Array
  • Object
show all
Defined in:
lib/openhab/core/things/thing.rb

Overview

Array wrapper class to allow searching a list of channels by channel id

Instance Method Summary collapse

Methods inherited from Array

wrap

Constructor Details

#initialize(thing, array) ⇒ ChannelsArray

Returns a new instance of ChannelsArray.



70
71
72
73
# File 'lib/openhab/core/things/thing.rb', line 70

def initialize(thing, array)
  super(array)
  @thing = thing
end

Instance Method Details

#[](index) ⇒ Channel?

Allows indexing by both integer as an array or channel id acting like a hash.

Parameters:

Returns:



79
80
81
82
83
84
# File 'lib/openhab/core/things/thing.rb', line 79

def [](index)
  return @thing.get_channel(index) if index.is_a?(ChannelUID)
  return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

  super
end