Sha256: b1f2bd84f0ed2cc5cabf9bd358576cdc8fd2483b3cfca75898909c1aeabca382
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module DMAPParser # The TagContainer class is a Tag which contains other Tags class TagContainer < Tag def initialize(type, value = []) super 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) return unless tag tag.type.container? ? tag : tag.value 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 nil 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.2.0 | lib/dmapparser/tag_container.rb |