Sha256: 0c4fce2aa5520539e7ef9cbee0cbaf360a95378003935fcdf6e79b282652f425

Contents?: true

Size: 1.35 KB

Versions: 23

Compression:

Stored size: 1.35 KB

Contents

module BrDanfe
  module CceLib
    class Document
      def initialize
        @document = BrDanfe::DocumentBuilder.build(
          page_size: 'A4',
          page_layout: :portrait,
          left_margin: 30,
          right_margin: 30,
          top_margin: 30,
          botton_margin: 30
        )

        @document.font 'tinos'
        @document.line_width = 0.3
      end

      def method_missing(method_name, *args, &block)
        if @document.respond_to? method_name
          @document.send method_name, *args, &block
        else
          super
        end
      end

      def respond_to_missing?(method_name, include_private = false)
        @document.respond_to?(method_name, include_private) || super
      end

      def box(height:, pad: 5)
        bounding_box([0, cursor], width: page_width, height: height) do
          pad(pad) { indent(pad) { yield if block_given? } }
          stroke_bounds
        end
      end

      def text(text, options = {})
        pad = options.delete(:pad) || 0
        options = { align: :left, size: 12, style: nil }.merge(options)

        pad(pad) do
          @document.text text, size: options[:size], style: options[:style],
            align: options[:align]
        end
      end

      private

      def page_width
        page.dimensions[2] - (page.margins[:left] + page.margins[:right])
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
br_danfe-1.2.1 lib/br_danfe/cce_lib/document.rb
br_danfe-1.2.0 lib/br_danfe/cce_lib/document.rb
br_danfe-1.1.0 lib/br_danfe/cce_lib/document.rb
br_danfe-1.0.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.20.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.19.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.18.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.8 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.7 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.6 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.5 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.4 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.3 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.2 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.1 lib/br_danfe/cce_lib/document.rb
br_danfe-0.17.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.16.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.15.1 lib/br_danfe/cce_lib/document.rb
br_danfe-0.15.0 lib/br_danfe/cce_lib/document.rb
br_danfe-0.14.5 lib/br_danfe/cce_lib/document.rb