lib/punchblock/event/complete.rb in punchblock-1.9.4 vs lib/punchblock/event/complete.rb in punchblock-2.0.0.beta1

- old
+ new

@@ -3,56 +3,39 @@ module Punchblock class Event class Complete < Event register :complete, :ext - def reason - element = find_first '*' - return unless element - RayoNode.import(element).tap do |reason| - reason.target_call_id = target_call_id - reason.component_id = component_id - end - end + attribute :reason - def reason=(other) - children.map(&:remove) - self << other - end + attribute :recording - def recording - element = find_first('//ns:recording', :ns => RAYO_NAMESPACES[:record_complete]) - return unless element - RayoNode.import(element).tap do |recording| - recording.target_call_id = target_call_id - recording.component_id = component_id + def inherit(xml_node) + if reason_node = xml_node.at_xpath('*') + self.reason = RayoNode.from_xml(reason_node).tap do |reason| + reason.target_call_id = target_call_id + reason.component_id = component_id + end end - end - def inspect_attributes # :nodoc: - [:reason, :recording] + super + if recording_node = xml_node.at_xpath('//ns:recording', ns: RAYO_NAMESPACES[:record_complete]) + self.recording = RayoNode.from_xml(recording_node).tap do |recording| + recording.target_call_id = target_call_id + recording.component_id = component_id + end + end + + super end class Reason < RayoNode - def self.new(options = {}) - super().tap do |new_node| - case options - when Nokogiri::XML::Node - new_node.inherit options - when Hash - options.each_pair { |k,v| new_node.send :"#{k}=", v } - end - end - end + attribute :name - def name - super.to_sym + def inherit(xml_node) + self.name = xml_node.name.to_sym + super end - - def inspect_attributes # :nodoc: - [:name] + super - end end class Stop < Reason register :stop, :ext_complete end @@ -62,20 +45,15 @@ end class Error < Reason register :error, :ext_complete - def details - text.strip - end + attribute :details - def details=(other) - self << other + def inherit(xml_node) + self.details = xml_node.text.strip + super end - - def inspect_attributes # :nodoc: - [:details] + super - end end - end # Complete + end end -end # Punchblock +end