Sha256: de97ef7db99b683169982253c0147f6021e216f4cb13d035cd06741330aa8d4a

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require_relative '../errors_warnings/warn_unexpected_params'

module Squib
  class Deck
    def safe_zone(opts = {})
      DSL::SafeZone.new(self, __callee__).run(opts)
    end
  end

  module DSL
    class SafeZone
      include WarnUnexpectedParams
      attr_reader :dsl_method, :deck

      def initialize(deck, dsl_method)
        @deck = deck
        @dsl_method = dsl_method
      end

      def self.accepted_params
        %i(x y width height margin angle
           x_radius y_radius radius
           fill_color stroke_color stroke_width stroke_strategy join dash cap
           range layout)
      end

      def run(opts)
        warn_if_unexpected opts
        safe_defaults = {
          margin: '0.25in',
          radius: '0.125in',
          stroke_color: :blue,
          fill_color: '#0000',
          stroke_width: 1.0,
          dash: '3 3',
        }
        new_opts = safe_defaults.merge(opts)
        margin = Args::UnitConversion.parse new_opts[:margin], @deck.dpi, @deck.cell_px
        new_opts[:x] = margin
        new_opts[:y] = margin
        new_opts[:width] = deck.width - (2 * margin)
        new_opts[:height] = deck.height - (2 * margin)
        new_opts.delete :margin
        deck.rect(new_opts)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
squib-0.19.0 lib/squib/dsl/safe_zone.rb
squib-0.19.0b lib/squib/dsl/safe_zone.rb
squib-0.19.0a lib/squib/dsl/safe_zone.rb