Sha256: 706f934205addf62175c70151ed72221c342c4287e4dbdfb425d7e9d5bf63992

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8

module Adhearsion
  module Rayo
    module Component
      class SendFax < ComponentNode
        register :sendfax, :fax

        class FaxDocument < RayoNode
          register :document, :fax

          attribute :url, String
          attribute :identity, String
          attribute :header, String
          attribute :pages, String

          def inherit(xml_node)
            super
            if pages = xml_node[:pages]
              self.pages = pages.split(',').map { |p| p.include?('-') ? Range.new(*p.split('-').map(&:to_i)) : p.to_i }
            end
            self
          end

          def rayo_attributes
            {
              'url'      => url,
              'identity' => identity,
              'header'   => header,
              'pages'    => rayo_pages
            }
          end

        private

          def rayo_pages
            pages ? pages.map { |p| p.is_a?(Range) ? "#{p.min}-#{p.max}" : p }.join(',') : nil
          end
        end

        def inherit(xml_node)
          document_nodes = xml_node.xpath 'ns:document', ns: self.class.registered_ns
          self.render_documents = document_nodes.to_a.map { |node| FaxDocument.from_xml node }

          super
       end

        def rayo_children(root)
          render_documents.each do |render_document|
            render_document.to_rayo root.parent
          end
          super
        end

        # @return [Document] the document to render
        attribute :render_documents, Array[FaxDocument], default: []

        def render_document=(other)
          self.render_documents = [other].compact
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-3.0.0.rc1 lib/adhearsion/rayo/component/send_fax.rb
adhearsion-3.0.0.beta2 lib/adhearsion/rayo/component/send_fax.rb
adhearsion-3.0.0.beta1 lib/adhearsion/rayo/component/send_fax.rb