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.



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

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:



87
88
89
90
91
92
# File 'lib/openhab/core/things/thing.rb', line 87

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