class DMAPParser::Builder
This class provides a DSL to create DMAP responses
Attributes
result[R]
Public Class Methods
method_missing(method, *args, &block)
click to toggle source
# File lib/dmapparser/builder.rb, line 11 def self.method_missing(method, *args, &block) new.send(method, *args, &block) end
new()
click to toggle source
# File lib/dmapparser/builder.rb, line 7 def initialize @dmap_stack = [] end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/dmapparser/builder.rb, line 15 def method_missing(method, *args, &block) tag = TagDefinition[method] return super if tag.nil? if block_given? || tag.container? fail "Tag #{tag} is not a container type" unless tag.container? build_container(tag, &block) else build_tag(tag, args) end end
Private Instance Methods
build_container(tag, &block)
click to toggle source
# File lib/dmapparser/builder.rb, line 38 def build_container(tag, &block) @dmap_stack << TagContainer.new(tag) instance_exec(&block) if @dmap_stack.length > 1 cur_tag = @dmap_stack.pop @dmap_stack.last.value << cur_tag else @result = @dmap_stack.pop end end
build_tag(tag, args)
click to toggle source
# File lib/dmapparser/builder.rb, line 29 def build_tag(tag, args) if @dmap_stack.length > 0 args = args.size > 1 ? args : args.first @dmap_stack.last.value << Tag.new(tag, args) else fail 'Cannot build DMAP without a valid container' end end