Sha256: 49fdc4e729994b4889f49ffefeddd1426664dc5f96f1f9b3f2114b95b0d562af

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8

module Punchblock
  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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/component/send_fax.rb
punchblock-2.7.3 lib/punchblock/component/send_fax.rb
punchblock-2.7.2 lib/punchblock/component/send_fax.rb
punchblock-2.7.1 lib/punchblock/component/send_fax.rb
punchblock-2.7.0 lib/punchblock/component/send_fax.rb
punchblock-2.6.0 lib/punchblock/component/send_fax.rb
punchblock-2.5.3 lib/punchblock/component/send_fax.rb
punchblock-2.5.2 lib/punchblock/component/send_fax.rb
punchblock-2.5.1 lib/punchblock/component/send_fax.rb
punchblock-2.5.0 lib/punchblock/component/send_fax.rb
punchblock-2.4.2 lib/punchblock/component/send_fax.rb
punchblock-2.4.0 lib/punchblock/component/send_fax.rb
punchblock-2.3.1 lib/punchblock/component/send_fax.rb
punchblock-2.3.0 lib/punchblock/component/send_fax.rb
punchblock-2.2.2 lib/punchblock/component/send_fax.rb
punchblock-2.2.1 lib/punchblock/component/send_fax.rb
punchblock-2.2.0 lib/punchblock/component/send_fax.rb