Sha256: 68cb8b649bd7d920bdd64959ac9b2b208253d64f4cad5cc1d0266ca665523675
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module DMAPParser # The TagContainer class is a Tag which contains other Tags class TagContainer < Tag def initialize(type = nil, value = []) super type, value end def inspect(level = 0) "#{' ' * level}#{type}:\n" + value.reduce('') do |a, e| a + e.inspect(level + 1).chomp + "\n" end end def get_value(key) return value[key] if key.is_a? Fixnum tag = get_tag(key) if tag.type.container? tag elsif !tag.nil? tag.value end end def get_tag(key) key = key.to_s value.find { |e| e.type.tag == key || e.type.name == key } end alias_method :[], :get_value def has?(key) !get_tag(key).nil? end def method_missing(method, *arguments, &block) if method =~ /(.*)\?$/ has?(Regexp.last_match[1]) elsif has?(method) get_value(method) else super end end def respond_to?(method) method.to_s.match(/(.*)\??$/) has?(Regexp.last_match[1]) || super end def to_a value end private def convert_value(value) value.reduce('') { |a, e| a + e.to_dmap } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dmapparser-0.0.1 | lib/dmapparser/tag_container.rb |