Class: Plushie::Type::Border::Spec
- Inherits:
-
Data
- Object
- Data
- Plushie::Type::Border::Spec
- Defined in:
- lib/plushie/type/border.rb
Overview
Immutable spec; use #with to create modified copies.
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(color: nil, width: 0, radius: 0) ⇒ Spec
constructor
A new instance of Spec.
-
#to_wire ⇒ Hash
Wire-ready map.
-
#with(**changes) ⇒ Object
Returns a copy with the given fields updated.
Constructor Details
#initialize(color: nil, width: 0, radius: 0) ⇒ Spec
Returns a new instance of Spec.
26 27 28 |
# File 'lib/plushie/type/border.rb', line 26 def initialize(color: nil, width: 0, radius: 0) super end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color
25 26 27 |
# File 'lib/plushie/type/border.rb', line 25 def color @color end |
#radius ⇒ Object (readonly)
Returns the value of attribute radius
25 26 27 |
# File 'lib/plushie/type/border.rb', line 25 def radius @radius end |
#width ⇒ Object (readonly)
Returns the value of attribute width
25 26 27 |
# File 'lib/plushie/type/border.rb', line 25 def width @width end |
Instance Method Details
#to_wire ⇒ Hash
Returns wire-ready map.
36 37 38 39 40 41 42 43 |
# File 'lib/plushie/type/border.rb', line 36 def to_wire if width.is_a?(Numeric) && width < 0 raise ArgumentError, "border width must be non-negative, got: #{width}" end h = {width: width, radius: encode_radius} h[:color] = color unless color.nil? h end |
#with(**changes) ⇒ Object
Returns a copy with the given fields updated.
31 32 33 |
# File 'lib/plushie/type/border.rb', line 31 def with(**changes) self.class.new(**to_h.merge(changes)) end |