Module: Sevgi::Graphics::Mixtures::Wrappers

Defined in:
lib/sevgi/graphics/mixtures/wrappers.rb

Overview

DSL wrappers for common SVG shapes and content patterns.

Instance Method Summary collapse

Instance Method Details

#css(hash = nil, **attributes) ⇒ Sevgi::Graphics::Element

Builds a style element with CSS content.

Parameters:

  • hash (Hash, nil) (defaults to: nil)

    CSS rules

  • attributes (Hash)

    style attributes or CSS rules when hash is nil

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when CSS rules are malformed, cyclic, cannot be stringified, or contain invalid encoding or illegal XML 1.0 characters



70
71
72
73
74
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 70

def css(hash = nil, **attributes)
  hash, attributes = attributes, {} unless hash

  style(Content.css(hash), type: "text/css", **attributes)
end

#HLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative horizontal line path.

Parameters:

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



81
82
83
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 81

def HLineBy(length:, x: 0, y: 0, **)
  path(d: "M #{x} #{y} h #{length}", **)
end

#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a horizontal line path ending at an absolute x coordinate.

Parameters:

  • x2 (Numeric)

    ending x coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



23
24
25
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 23

def HLineTo(x2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} H #{x2}", **)
end

#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative line path from angle and length.

Parameters:

  • angle (Numeric)

    angle in degrees

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



58
59
60
61
62
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 58

def LineBy(angle:, length:, x: 0, y: 0, **)
  dx = length * ::Math.cos(angle.to_f / 180 * ::Math::PI)
  dy = length * ::Math.sin(angle.to_f / 180 * ::Math::PI)
  path(d: "M #{x} #{y} l #{dx} #{dy}", **)
end

#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a line path ending at an absolute point.

Parameters:

  • x2 (Numeric)

    ending x coordinate

  • y2 (Numeric)

    ending y coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



14
15
16
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 14

def LineTo(x2:, y2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} L #{x2} #{y2}", **)
end

#square(length:) ⇒ Sevgi::Graphics::Element

Builds a square rect.

Parameters:

  • length (Numeric)

    side length

Returns:



88
89
90
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 88

def square(length:, **)
  rect(width: length, height: length, **)
end

#Symbol(name, **kwargs) { ... } ⇒ Sevgi::Graphics::Element

Builds a titled SVG symbol.

Parameters:

  • name (String)

    human-readable symbol name

  • kwargs (Hash)

    symbol attributes

Yields:

  • evaluates the drawing DSL in the symbol element

Yield Returns:

  • (Object)

    ignored block result

Returns:



33
34
35
36
37
38
39
40
41
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 33

def Symbol(name, **kwargs, &block)
  id = (words = name.split).map(&:downcase).join("-")
  title = words.map(&:capitalize).join(" ")

  symbol(id:, **kwargs) do
    title(title)
    Within(&block)
  end
end

#VLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative vertical line path.

Parameters:

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



97
98
99
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 97

def VLineBy(length:, x: 0, y: 0, **)
  path(d: "M #{x} #{y} v #{length}", **)
end

#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a vertical line path ending at an absolute y coordinate.

Parameters:

  • y2 (Numeric)

    ending y coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



48
49
50
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 48

def VLineTo(y2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} V #{y2}", **)
end