Class: Postsvg::Svg::Elements::Svg

Inherits:
Postsvg::Svg::Element show all
Defined in:
lib/postsvg/svg/elements/svg.rb

Constant Summary collapse

ELEMENT_NAME =
"svg"

Constants inherited from Postsvg::Svg::Element

Postsvg::Svg::Element::REGISTRY

Instance Attribute Summary collapse

Attributes inherited from Postsvg::Svg::Element

#attributes, #clip_path_id, #fill, #stroke, #stroke_paint, #transform

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Postsvg::Svg::Element

#default_fill, #element_name, register, registry

Constructor Details

#initialize(viewbox: nil, width: nil, height: nil, children: [], **rest) ⇒ Svg

Returns a new instance of Svg.



12
13
14
15
16
17
18
# File 'lib/postsvg/svg/elements/svg.rb', line 12

def initialize(viewbox: nil, width: nil, height: nil, children: [], **rest)
  super(**rest)
  @viewbox = viewbox
  @width = width
  @height = height
  @children = children.freeze
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/postsvg/svg/elements/svg.rb', line 10

def children
  @children
end

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/postsvg/svg/elements/svg.rb', line 10

def height
  @height
end

#viewboxObject (readonly)

Returns the value of attribute viewbox.



10
11
12
# File 'lib/postsvg/svg/elements/svg.rb', line 10

def viewbox
  @viewbox
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'lib/postsvg/svg/elements/svg.rb', line 10

def width
  @width
end

Class Method Details

.from_node(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/postsvg/svg/elements/svg.rb', line 20

def self.from_node(node)
  children = node.element_children.map { |c| Element.from_node(c) }
  vb = node["viewBox"]&.split(/[\s,]+/)&.map(&:to_f)
  new(viewbox: (vb if vb&.length == 4),
      width: AttributeParser.length(node["width"]),
      height: AttributeParser.length(node["height"]),
      children: children,
      transform: TransformList.parse(node["transform"]),
      clip_path_id: parse_clip_path_id(node["clip-path"]))
end