Class: Plushie::Type::Border::Spec

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/type/border.rb

Overview

Immutable spec; use #with to create modified copies.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorObject (readonly)

Returns the value of attribute color

Returns:

  • (Object)

    the current value of color



25
26
27
# File 'lib/plushie/type/border.rb', line 25

def color
  @color
end

#radiusObject (readonly)

Returns the value of attribute radius

Returns:

  • (Object)

    the current value of radius



25
26
27
# File 'lib/plushie/type/border.rb', line 25

def radius
  @radius
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



25
26
27
# File 'lib/plushie/type/border.rb', line 25

def width
  @width
end

Instance Method Details

#to_wireHash

Returns wire-ready map.

Returns:

  • (Hash)

    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