Class: DACPClient::TagContainer
- Inherits:
-
Tag
- Object
- Struct
- Tag
- DACPClient::TagContainer
show all
- Defined in:
- lib/dacpclient/tag_container.rb
Overview
The TagContainer class is a Tag which contains other Tags
Instance Attribute Summary
Attributes inherited from Tag
#type, #value
Instance Method Summary
collapse
Methods inherited from Tag
#to_dmap, #to_s
Constructor Details
#initialize(type = nil, value = []) ⇒ TagContainer
Returns a new instance of TagContainer.
4
5
6
|
# File 'lib/dacpclient/tag_container.rb', line 4
def initialize(type = nil, value = [])
super type, value
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/dacpclient/tag_container.rb', line 37
def method_missing(method, *arguments, &block)
if method =~ /(.*)\?$/
has?($1)
elsif has?(method)
get_value(method)
else
super
end
end
|
Instance Method Details
#get_value(key) ⇒ Object
Also known as:
[]
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/dacpclient/tag_container.rb', line 14
def get_value(key)
return value[key] if key.is_a? Fixnum
key = key.to_s
val = value.find { |e| e.type.tag == key }
val = value.find { |e| e.type.name == key } if val.nil?
if val.type.type == :container
val
elsif !val.nil?
val.value
end
end
|
#has?(key) ⇒ Boolean
30
31
32
33
34
35
|
# File 'lib/dacpclient/tag_container.rb', line 30
def has?(key)
key = key.to_s
val = value.find { |e| e.type.tag == key }
val = value.find { |e| e.type.name == key } if val.nil?
!val.nil?
end
|
#inspect(level = 0) ⇒ Object
8
9
10
11
12
|
# File 'lib/dacpclient/tag_container.rb', line 8
def inspect(level = 0)
"#{' ' * level}#{type}:\n" + value.reduce('') do |a, e|
a + e.inspect(level + 1).chomp + "\n"
end
end
|
#to_a ⇒ Object
47
48
49
|
# File 'lib/dacpclient/tag_container.rb', line 47
def to_a
value
end
|