Class: DMAPParser::TagContainer
- Inherits:
-
Tag
- Object
- Struct
- Tag
- DMAPParser::TagContainer
show all
- Defined in:
- lib/dmapparser/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, value = []) ⇒ TagContainer
Returns a new instance of TagContainer.
4
5
6
|
# File 'lib/dmapparser/tag_container.rb', line 4
def initialize(type, value = [])
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_arguments, &_block) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/dmapparser/tag_container.rb', line 32
def method_missing(method, *_arguments, &_block)
if method =~ /(.*)\?$/
has?(Regexp.last_match[1])
elsif has?(method)
get_value(method)
else
nil
end
end
|
Instance Method Details
#get_tag(key) ⇒ Object
21
22
23
24
|
# File 'lib/dmapparser/tag_container.rb', line 21
def get_tag(key)
key = key.to_s
value.find { |e| e.type.tag == key || e.type.name == key }
end
|
#get_value(key) ⇒ Object
Also known as:
[]
14
15
16
17
18
19
|
# File 'lib/dmapparser/tag_container.rb', line 14
def get_value(key)
return value[key] if key.is_a? Fixnum
tag = get_tag(key)
return unless tag
tag.type.container? ? tag : tag.value
end
|
#has?(key) ⇒ Boolean
28
29
30
|
# File 'lib/dmapparser/tag_container.rb', line 28
def has?(key)
!get_tag(key).nil?
end
|
#inspect(level = 0) ⇒ Object
8
9
10
11
12
|
# File 'lib/dmapparser/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
|
#respond_to?(method) ⇒ Boolean
42
43
44
45
|
# File 'lib/dmapparser/tag_container.rb', line 42
def respond_to?(method)
method.to_s.match(/(.*)\??$/)
has?(Regexp.last_match[1]) || super
end
|
#to_a ⇒ Object
47
48
49
|
# File 'lib/dmapparser/tag_container.rb', line 47
def to_a
value
end
|