Class: Squib::Args::ScaleBox

Inherits:
Object
  • Object
show all
Includes:
ArgLoader, XYWHShorthands
Defined in:
lib/squib/args/scale_box.rb

Constant Summary

Constants included from XYWHShorthands

XYWHShorthands::DECK_DIV_REGEX, XYWHShorthands::DECK_MINUS_REGEX, XYWHShorthands::DECK_ONLY, XYWHShorthands::DECK_PLUS_REGEX, XYWHShorthands::MIDDLE_MINUS_REGEX, XYWHShorthands::MIDDLE_ONLY, XYWHShorthands::MIDDLE_PLUS_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XYWHShorthands

#apply_shorthands

Methods included from ArgLoader

#[], #convert_units, #deck_conf, #defaultify, #expand_and_set_and_defaultify, #expandable_singleton?, #extract!, #load!, #prep_layout_args, #validate

Class Method Details

.expanding_parametersObject



20
21
22
# File 'lib/squib/args/scale_box.rb', line 20

def self.expanding_parameters
  parameters.keys # all of them
end

.parametersObject



13
14
15
16
17
18
# File 'lib/squib/args/scale_box.rb', line 13

def self.parameters
  {
    x: 0, y: 0,
    width: :native, height: :native
  }
end

.params_with_unitsObject



24
25
26
# File 'lib/squib/args/scale_box.rb', line 24

def self.params_with_units
  parameters.keys # all of them
end

Instance Method Details

#validate_height(arg, i) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/squib/args/scale_box.rb', line 43

def validate_height(arg, i)
  return @deck.height if arg.to_s == 'deck'
  return :native      if arg.to_s == 'native'
  arg = apply_shorthands(arg, @deck, axis: :y)
  return arg          if arg.respond_to? :to_f
  if arg.to_s == 'scale'
    raise 'if height is \'scale\', width must be a number' unless width[i].respond_to? :to_f
    return arg
  end
  raise 'height must be a number, :scale, :native, or :deck'
end

#validate_width(arg, i) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/squib/args/scale_box.rb', line 31

def validate_width(arg, i)
  return @deck.width if arg.to_s == 'deck'
  return :native     if arg.to_s == 'native'
  arg = apply_shorthands(arg, @deck, axis: :x)
  return arg         if arg.respond_to? :to_f
  if arg.to_s == 'scale'
    raise 'if width is :scale, height must be a number' unless height[i].respond_to? :to_f
    return arg
  end
  raise 'width must be a number, :scale, :native, or :deck'
end

#validate_x(arg, i) ⇒ Object



28
# File 'lib/squib/args/scale_box.rb', line 28

def validate_x(arg, i) apply_shorthands(arg, @deck, axis: :x) end

#validate_y(arg, _i) ⇒ Object



29
# File 'lib/squib/args/scale_box.rb', line 29

def validate_y(arg,_i) apply_shorthands(arg, @deck, axis: :y) end