Sha256: 2c367542e9b5d207de6eb2342f2f183ffa09656ad36bf26295f73a03a61bde1b

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Postdoc
  # Different prints require different settings. This class is used instead of
  # passing options arguments throughout all of the code.
  class PrintSettings
    def initialize(
        header_template: '',
        footer_template: '',
        landscape: false,
        print_background: true,
        margin_top: 1,
        margin_bottom: 1,
        margin_left: 1,
        margin_right: 1
    )
      @header_template = header_template
      @footer_template = footer_template
      @landscape = landscape
      @print_background = print_background
      @margin_top = margin_top
      @margin_bottom = margin_bottom
      @margin_left = margin_left
      @margin_right = margin_right
    end

    def to_cmd
      { landscape: @landscape,
        printBackground: true,
        marginTop: @margin_top,
        marginBottom: @margin_bottom,
        marginLeft: @margin_left,
        marginRight: @margin_right,
        displayHeaderFooter: display_header_and_footer?,
        headerTemplate: @header_template,
        footerTemplate: @footer_template }
    end

    private

    def display_header_and_footer?
      @header_template.present? || @footer_template.present?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
postdoc-0.4.0 lib/postdoc/print_settings.rb
postdoc-0.3.9 lib/postdoc/print_settings.rb
postdoc-0.3.8 lib/postdoc/print_settings.rb