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.



67
68
69
70
# File 'lib/openhab/core/things/thing.rb', line 67

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

Instance Method Details

#[](index) ⇒ Object

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

Parameters:



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

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