class UnifiProtect::CameraCollection
Constants
- FILTERS
Attributes
cameras[R]
Public Class Methods
new(cameras = [])
click to toggle source
# File lib/unifi_protect/camera_collection.rb, line 28 def initialize(cameras = []) @cameras = cameras end
Public Instance Methods
fetch(**attrs)
click to toggle source
# File lib/unifi_protect/camera_collection.rb, line 67 def fetch(**attrs) match(**attrs).first end
filter(name, value = true)
click to toggle source
# File lib/unifi_protect/camera_collection.rb, line 71 def filter(name, value = true) return CameraCollection.new if @cameras.empty? raise 'unknown filter' unless FILTERS.include?(name.to_sym) CameraCollection.new(@cameras.select { |c| c.send(FILTERS.fetch(name.to_sym)) == value }) end
match(**attrs)
click to toggle source
# File lib/unifi_protect/camera_collection.rb, line 57 def match(**attrs) return CameraCollection.new(cameras) if attrs.empty? CameraCollection.new( @cameras.select do |camera| attrs.any? { |name, matcher| camera.match(name, matcher) } end ) end
method_missing(method_name, *args)
click to toggle source
Calls superclass method
# File lib/unifi_protect/camera_collection.rb, line 51 def method_missing(method_name, *args) return filter(method_name, *args) if FILTERS.include?(method_name) super end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/unifi_protect/camera_collection.rb, line 45 def respond_to_missing?(method_name, include_private = false) return true if FILTERS.include?(method_name) super end