Class: MPD::Controller::Channels

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mpd/controller/channels.rb

Defined Under Namespace

Classes: Channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Channels

Returns a new instance of Channels.



48
49
50
51
# File 'lib/mpd/controller/channels.rb', line 48

def initialize (controller)
	@controller = controller
	@channels   = []
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



46
47
48
# File 'lib/mpd/controller/channels.rb', line 46

def controller
  @controller
end

Instance Method Details

#[](name, sub = true) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/mpd/controller/channels.rb', line 71

def [] (name, sub = true)
	subscribe name if sub

	Channel.new(self, name).tap {|channel|
		@channels << WeakRef.new(channel)
	}
end

#eachObject



61
62
63
64
65
66
67
68
69
# File 'lib/mpd/controller/channels.rb', line 61

def each
	return to_enum unless block_given?

	each_name {|name|
		yield self[name]
	}

	self
end

#each_name(&block) ⇒ Object



57
58
59
# File 'lib/mpd/controller/channels.rb', line 57

def each_name (&block)
	names.each(&block)
end

#namesObject



53
54
55
# File 'lib/mpd/controller/channels.rb', line 53

def names
	controller.do_and_raise_if_needed(:channels).map(&:last)
end

#send_message(name, text) ⇒ Object



87
88
89
# File 'lib/mpd/controller/channels.rb', line 87

def send_message (name, text)
	controller.do_and_raise_if_needed :sendmessage, name, text
end

#subscribe(name) ⇒ Object



79
80
81
# File 'lib/mpd/controller/channels.rb', line 79

def subscribe (name)
	controller.do_and_raise_if_needed :subscribe, name
end

#unsubscribe(name) ⇒ Object



83
84
85
# File 'lib/mpd/controller/channels.rb', line 83

def unsubscribe (name)
	controller.do_and_raise_if_needed :unsubscribe, name
end