Class: Laser::Cutter::Options
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Laser::Cutter::Options
- Defined in:
- lib/laser/cutter/options.rb
Overview
Everything a box can be asked for, typed. This is what a Ruby program hands to render or write.
Values are coerced, so the Strings of a web form will do, and an instance cannot be changed: #new(lid: :plain) returns a changed copy. Keys may be Strings or Symbols. A key it does not know, a value of the wrong type or a dimension left out all raise, at once, before anything is drawn.
The distances left nil take the default for the units: a kerf of 0.0024in, a margin of 0.125in, a padding of 0.1in, a stroke of 0.001in, and a notch three times the thickness.
Constant Summary collapse
- REQUIRED =
The dimensions a box cannot be drawn without.
%i[width height depth thickness].freeze
- MAXIMUM_CHOICES =
The longest list of allowed values an error spells out.
5
Instance Attribute Summary collapse
-
#depth ⇒ Float
readonly
Internal depth of the box.
-
#file ⇒ String?
readonly
The file write writes.
-
#format ⇒ String?
readonly
"pdf" or "svg"; nil for a PDF, or for what the extension of the file says.
-
#front_height ⇒ Float?
readonly
Internal height at the front of a sloped box, where the slope begins; required with a slope, and 0 starts the slope at the bottom.
-
#height ⇒ Float
readonly
Internal height of the box.
-
#inside_box ⇒ Boolean
readonly
Whether the box is also drawn without kerf, in red.
-
#kerf ⇒ Float?
readonly
Width of the cut; nil for the default.
-
#lid ⇒ String
readonly
"full", "back" or "plain": notched on every side, into the back wall only, or on no side.
-
#margin ⇒ Float?
readonly
Margin from the edge of the page; nil for the default.
-
#metadata ⇒ Boolean
readonly
Whether the settings of the box are printed on the page.
-
#notch ⇒ Float?
readonly
Notch length, a guide only; nil for three times the thickness.
-
#padding ⇒ Float?
readonly
Space between the panels; nil for the default.
-
#page_layout ⇒ String
readonly
"portrait" or "landscape", for a PDF.
-
#page_size ⇒ String?
readonly
A page size such as "A4", for a PDF; nil to fit the box.
-
#slope ⇒ Float?
readonly
Angle of a sloped front above horizontal, in degrees, above 0 and below 90; nil for the box with six panels.
-
#stroke ⇒ Float?
readonly
Stroke width of the lines; nil for the default.
-
#thickness ⇒ Float
readonly
Thickness of the material.
-
#units ⇒ String
readonly
"in" or "mm", the units of every distance here.
-
#width ⇒ Float
readonly
Internal width of the box.
Class Method Summary collapse
Instance Method Summary collapse
-
#to_configuration ⇒ Configuration
The same settings, as the renderers take them.
Instance Attribute Details
#depth ⇒ Float (readonly)
Returns internal depth of the box.
49 |
# File 'lib/laser/cutter/options.rb', line 49 attribute :depth, Types::Length |
#file ⇒ String? (readonly)
Returns the file Laser::Cutter.write writes.
88 |
# File 'lib/laser/cutter/options.rb', line 88 attribute? :file, Types.optional(Types::Coercible::String) |
#format ⇒ String? (readonly)
Returns "pdf" or "svg"; nil for a PDF, or for what the extension of the file says.
84 |
# File 'lib/laser/cutter/options.rb', line 84 attribute? :format, Types.optional(Types::Format) |
#front_height ⇒ Float? (readonly)
Returns internal height at the front of a sloped box, where the slope begins; required with a slope, and 0 starts the slope at the bottom.
63 |
# File 'lib/laser/cutter/options.rb', line 63 attribute? :front_height, Types.optional(Types::Allowance) |
#height ⇒ Float (readonly)
Returns internal height of the box.
45 |
# File 'lib/laser/cutter/options.rb', line 45 attribute :height, Types::Length |
#inside_box ⇒ Boolean (readonly)
Returns whether the box is also drawn without kerf, in red.
116 |
# File 'lib/laser/cutter/options.rb', line 116 attribute :inside_box, Types::Params::Bool.default(false) |
#kerf ⇒ Float? (readonly)
Returns width of the cut; nil for the default.
71 |
# File 'lib/laser/cutter/options.rb', line 71 attribute? :kerf, Types.optional(Types::Allowance) |
#lid ⇒ String (readonly)
Returns "full", "back" or "plain": notched on every side, into the back wall only, or on no side. On a sloped box it is the tilted panel: "full" notches it into the side walls, "plain" lays it on them.
80 |
# File 'lib/laser/cutter/options.rb', line 80 attribute :lid, Types::Lid |
#margin ⇒ Float? (readonly)
Returns margin from the edge of the page; nil for the default.
92 |
# File 'lib/laser/cutter/options.rb', line 92 attribute? :margin, Types.optional(Types::Allowance) |
#metadata ⇒ Boolean (readonly)
Returns whether the settings of the box are printed on the page.
112 |
# File 'lib/laser/cutter/options.rb', line 112 attribute :metadata, Types::Params::Bool.default(true) |
#notch ⇒ Float? (readonly)
Returns notch length, a guide only; nil for three times the thickness.
67 |
# File 'lib/laser/cutter/options.rb', line 67 attribute? :notch, Types.optional(Types::Length) |
#padding ⇒ Float? (readonly)
Returns space between the panels; nil for the default.
96 |
# File 'lib/laser/cutter/options.rb', line 96 attribute? :padding, Types.optional(Types::Allowance) |
#page_layout ⇒ String (readonly)
Returns "portrait" or "landscape", for a PDF.
108 |
# File 'lib/laser/cutter/options.rb', line 108 attribute :page_layout, Types::PageLayout |
#page_size ⇒ String? (readonly)
Returns a page size such as "A4", for a PDF; nil to fit the box.
104 |
# File 'lib/laser/cutter/options.rb', line 104 attribute? :page_size, Types.optional(Types::PageSize) |
#slope ⇒ Float? (readonly)
Returns angle of a sloped front above horizontal, in degrees, above 0 and below 90; nil for the box with six panels.
58 |
# File 'lib/laser/cutter/options.rb', line 58 attribute? :slope, Types.optional(Types::Slope) |
#stroke ⇒ Float? (readonly)
Returns stroke width of the lines; nil for the default.
100 |
# File 'lib/laser/cutter/options.rb', line 100 attribute? :stroke, Types.optional(Types::Length) |
#thickness ⇒ Float (readonly)
Returns thickness of the material.
53 |
# File 'lib/laser/cutter/options.rb', line 53 attribute :thickness, Types::Length |
Class Method Details
.new(attributes = {}) ⇒ Options
122 123 124 125 126 127 128 129 |
# File 'lib/laser/cutter/options.rb', line 122 def new(attributes = {}, *) return attributes if attributes.is_a?(self) require_dimensions!(attributes) if attributes.respond_to?(:to_h) super.tap { || Sloped::Request.validate!(.to_h) } rescue Dry::Struct::Error => e raise InvalidOption, explain(e) end |
Instance Method Details
#to_configuration ⇒ Configuration
Returns the same settings, as the renderers take them.
170 171 172 |
# File 'lib/laser/cutter/options.rb', line 170 def to_configuration Configuration.new(to_h.except(:format, :inside_box).merge(debug: inside_box)) end |