Class: Squib::Args::Sheet Private

Inherits:
Object
  • Object
show all
Includes:
ArgLoader, ColorValidator, DirValidator
Defined in:
lib/squib/args/sheet.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DirValidator

#ensure_dir_created

Methods included from ColorValidator

#colorify

Methods included from ArgLoader

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

Constructor Details

#initialize(custom_colors = {}, dsl_method_defaults = {}, deck_size = 1, dpi = 300) ⇒ Sheet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Sheet



15
16
17
18
19
20
# File 'lib/squib/args/sheet.rb', line 15

def initialize(custom_colors = {}, dsl_method_defaults = {}, deck_size = 1, dpi = 300)
  @custom_colors = custom_colors
  @dsl_method_defaults = dsl_method_defaults
  @deck_size = deck_size
  @dpi = dpi
end

Class Method Details

.expanding_parametersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
# File 'lib/squib/args/sheet.rb', line 50

def self.expanding_parameters
  [] # none of them
end

.parametersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/squib/args/sheet.rb', line 22

def self.parameters
  {
    count_format: '%02d',
    crop_margin_bottom: 0,
    crop_margin_left: 0,
    crop_margin_right: 0,
    crop_margin_top: 0,
    crop_marks: false,
    crop_stroke_color: :black,
    crop_stroke_dash: '',
    crop_stroke_width: 1.5,
    dir: '_output',
    file: 'sheet.png',
    fill_color: :white,
    gap: 0,
    height: 2550,
    margin: 75,
    prefix: 'sheet_',
    rows: :infinite,
    columns: 5,
    trim_radius: 38,
    trim: 0,
    width: 3300,
    range: :all,
    rtl: false,
  }
end

.params_with_unitsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
59
# File 'lib/squib/args/sheet.rb', line 54

def self.params_with_units
  [ :crop_margin_bottom, :crop_margin_left, :crop_margin_right,
    :crop_margin_top, :gap, :height, :margin, :trim_radius, :trim,
    :width
  ]
end

Instance Method Details

#crop_coords(x, y, deck_w, deck_h) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/squib/args/sheet.rb', line 104

def crop_coords(x, y, deck_w, deck_h)
  case crop_marks
  when false
    []
  when :full
    [
      {
        # Vertical, Left
        x1: x + trim + crop_margin_left, y1: 0,
        x2: x + trim + crop_margin_left, y2: height - margin + 1
      },
      {
        # Vertical, Right
        x1: x + deck_w - trim - crop_margin_right, y1: 0,
        x2: x + deck_w - trim - crop_margin_right, y2: height - margin + 1
      },
      {
        # Horizontal, Top
        x1: 0                 , y1: y + trim + crop_margin_top,
        x2: width - margin + 1, y2: y + trim + crop_margin_top
      },
      {
        # Horizontal, Bottom
        x1: 0         , y1: y + deck_h - trim - crop_margin_bottom,
        x2: width - margin + 1, y2: y + deck_h - trim - crop_margin_bottom
      },
    ]
  else # e.g. :margin
    [
      { # Vertical, Upper-left
        x1: x + trim + crop_margin_left, y1: 0,
        x2: x + trim + crop_margin_left, y2: margin - 1
      },
      { # Vertical , Upper-right
        x1: x + deck_w - trim - crop_margin_right, y1: 0,
        x2: x + deck_w - trim - crop_margin_right, y2: margin - 1
      },
      { # Vertical , Lower-left
        x1: x + trim + crop_margin_left, y1: height,
        x2: x + trim + crop_margin_left, y2: height - margin + 1
      },
      { # Vertical , Lower-right
        x1: x + deck_w - trim - crop_margin_right, y1: height,
        x2: x + deck_w - trim - crop_margin_right, y2: height - margin + 1
      },
      { # Horizontal, Upper-left
        x1: 0         , y1: y + trim + crop_margin_top,
        x2: margin - 1, y2: y + trim + crop_margin_top
      },
      { # Horizontal, Upper-Right
        x1: width             , y1: y + trim + crop_margin_top,
        x2: width - margin + 1, y2: y + trim + crop_margin_top
      },
      { # Horizontal, Lower-Left
        x1: 0         , y1: y + deck_h - trim - crop_margin_bottom,
        x2: margin - 1, y2: y + deck_h - trim - crop_margin_bottom
      },
      { # Horizontal, Lower-Right
        x1: width,              y1: y + deck_h - trim - crop_margin_bottom,
        x2: width - margin + 1, y2: y + deck_h - trim - crop_margin_bottom
      },
    ]
  end
end

#full_filename(i = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



96
97
98
99
100
101
102
# File 'lib/squib/args/sheet.rb', line 96

def full_filename(i=nil)
  if i.nil?
    "#{dir}/#{file}"
  else
    "#{dir}/#{prefix}#{count_format % i}.png"
  end
end

#validate_columns(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
# File 'lib/squib/args/sheet.rb', line 79

def validate_columns(arg)
  raise 'columns must be an integer' unless arg.respond_to? :to_i
  arg.to_i
end

#validate_crop_marks(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
# File 'lib/squib/args/sheet.rb', line 67

def validate_crop_marks(arg)
  arg.to_s.downcase.to_sym unless arg == false
end

#validate_crop_stroke_dash(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
# File 'lib/squib/args/sheet.rb', line 61

def validate_crop_stroke_dash(arg)
  arg.to_s.split.collect do |x|
    UnitConversion.parse(x, @dpi).to_f
  end
end

#validate_dir(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# File 'lib/squib/args/sheet.rb', line 75

def validate_dir(arg)
  ensure_dir_created(arg)
end

#validate_fill_color(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



71
72
73
# File 'lib/squib/args/sheet.rb', line 71

def validate_fill_color(arg)
  colorify(arg, @custom_colors)
end

#validate_rows(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/squib/args/sheet.rb', line 84

def validate_rows(arg)
  raise 'columns must be an integer' unless columns.respond_to? :to_i
  count = if range == :all
            @deck_size
          else
            count = range.to_a.length
          end
  return 1 if count <= columns
  return arg if arg.respond_to? :to_i
  (count.to_f / columns.to_f).ceil
end