Class: Plushie::Canvas::Shape::Stroke

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/canvas/shape/stroke.rb

Overview

Canvas stroke descriptor with color, width, and optional cap/join/dash.

Examples:

Stroke.new(color: "#000", width: 2)
Stroke.new(color: "#000", width: 2, cap: "round", join: "miter")
Stroke.new(color: "#000", width: 1, dash: Dash.new(segments: [4, 2], offset: 0))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color:, width:, cap: nil, join: nil, dash: nil) ⇒ Stroke

Returns a new instance of Stroke.



13
14
15
# File 'lib/plushie/canvas/shape/stroke.rb', line 13

def initialize(color:, width:, cap: nil, join: nil, dash: nil)
  super
end

Instance Attribute Details

#capObject (readonly)

Returns the value of attribute cap

Returns:

  • (Object)

    the current value of cap



12
13
14
# File 'lib/plushie/canvas/shape/stroke.rb', line 12

def cap
  @cap
end

#colorObject (readonly)

Returns the value of attribute color

Returns:

  • (Object)

    the current value of color



12
13
14
# File 'lib/plushie/canvas/shape/stroke.rb', line 12

def color
  @color
end

#dashObject (readonly)

Returns the value of attribute dash

Returns:

  • (Object)

    the current value of dash



12
13
14
# File 'lib/plushie/canvas/shape/stroke.rb', line 12

def dash
  @dash
end

#joinObject (readonly)

Returns the value of attribute join

Returns:

  • (Object)

    the current value of join



12
13
14
# File 'lib/plushie/canvas/shape/stroke.rb', line 12

def join
  @join
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



12
13
14
# File 'lib/plushie/canvas/shape/stroke.rb', line 12

def width
  @width
end

Instance Method Details

#[](key) ⇒ Object

Backward-compatible hash-style access.



18
# File 'lib/plushie/canvas/shape/stroke.rb', line 18

def [](key) = to_wire[key]

#to_wireHash

Returns wire-ready stroke map.

Returns:

  • (Hash)

    wire-ready stroke map



21
22
23
24
25
26
27
# File 'lib/plushie/canvas/shape/stroke.rb', line 21

def to_wire
  h = {color: color, width: width}
  h[:cap] = cap if cap
  h[:join] = join if join
  h[:dash] = dash.respond_to?(:to_wire) ? dash.to_wire : dash if dash
  h
end