Class: Squib::DSL::SafeZone

Inherits:
Object
  • Object
show all
Includes:
WarnUnexpectedParams
Defined in:
lib/squib/dsl/safe_zone.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WarnUnexpectedParams

#warn_if_unexpected

Constructor Details

#initialize(deck, dsl_method) ⇒ SafeZone

Returns a new instance of SafeZone.



15
16
17
18
# File 'lib/squib/dsl/safe_zone.rb', line 15

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

Instance Attribute Details

#deckObject (readonly)



13
14
15
# File 'lib/squib/dsl/safe_zone.rb', line 13

def deck
  @deck
end

#dsl_methodObject (readonly)



13
14
15
# File 'lib/squib/dsl/safe_zone.rb', line 13

def dsl_method
  @dsl_method
end

Class Method Details

.accepted_paramsObject



20
21
22
23
24
25
# File 'lib/squib/dsl/safe_zone.rb', line 20

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

Instance Method Details

#run(opts) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/squib/dsl/safe_zone.rb', line 27

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