Class: Plushie::Canvas::Shape::Path

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/canvas/shape/path.rb,
sig/plushie/canvas/shape.rbs

Overview

Path shape built from segments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commands:, fill: nil, stroke: nil, stroke_width: nil, opacity: nil) ⇒ Path

Returns a new instance of Path.

Parameters:

  • commands: (Array[Array[untyped]])
  • fill: (Object) (defaults to: nil)
  • stroke: (Object) (defaults to: nil)
  • stroke_width: (Numeric, nil) (defaults to: nil)
  • opacity: (Numeric, nil) (defaults to: nil)


8
9
10
# File 'lib/plushie/canvas/shape/path.rb', line 8

def initialize(commands:, fill: nil, stroke: nil, stroke_width: nil, opacity: nil)
  super
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands

Returns:

  • (Object)

    the current value of commands



7
8
9
# File 'lib/plushie/canvas/shape/path.rb', line 7

def commands
  @commands
end

#fillObject (readonly)

Returns the value of attribute fill

Returns:

  • (Object)

    the current value of fill



7
8
9
# File 'lib/plushie/canvas/shape/path.rb', line 7

def fill
  @fill
end

#opacityObject (readonly)

Returns the value of attribute opacity

Returns:

  • (Object)

    the current value of opacity



7
8
9
# File 'lib/plushie/canvas/shape/path.rb', line 7

def opacity
  @opacity
end

#strokeObject (readonly)

Returns the value of attribute stroke

Returns:

  • (Object)

    the current value of stroke



7
8
9
# File 'lib/plushie/canvas/shape/path.rb', line 7

def stroke
  @stroke
end

#stroke_widthObject (readonly)

Returns the value of attribute stroke_width

Returns:

  • (Object)

    the current value of stroke_width



7
8
9
# File 'lib/plushie/canvas/shape/path.rb', line 7

def stroke_width
  @stroke_width
end

Instance Method Details

#[](key) ⇒ Object

Access shape properties by key.

Parameters:

  • key (Symbol)

Returns:

  • (Object)


16
# File 'lib/plushie/canvas/shape/path.rb', line 16

def [](key) = to_wire[key]

#to_wireHash[Symbol, untyped]

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.

Encode shape for the wire protocol.

Returns:

  • (Hash[Symbol, untyped])


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

def to_wire
  h = {type: "path", commands: commands}
  h[:fill] = fill if fill
  h[:stroke] = stroke if stroke
  h[:stroke_width] = stroke_width if stroke_width
  h[:opacity] = opacity if opacity
  h
end