Class: Vectory::Svg

Inherits:
Vector show all
Defined in:
lib/vectory/svg.rb

Constant Summary collapse

SVG_NS =
"http://www.w3.org/2000/svg"

Instance Attribute Summary

Attributes inherited from Vector

#initial_path

Attributes inherited from Image

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vector

#convert_with_inkscape, #file_size, from_datauri, from_path, #height, #mime, #path, #size, #to_uri, #width, #write

Methods inherited from Image

from_content, from_path

Constructor Details

#initialize(content = nil, initial_path = nil) ⇒ Svg

Returns a new instance of Svg.



28
29
30
31
32
# File 'lib/vectory/svg.rb', line 28

def initialize(content = nil, initial_path = nil)
  super

  self.content = content
end

Class Method Details

.default_extensionObject



9
10
11
# File 'lib/vectory/svg.rb', line 9

def self.default_extension
  "svg"
end

.from_node(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/vectory/svg.rb', line 17

def self.from_node(node)
  if node.elements&.first&.name == "svg"
    return from_content(node.children.to_xml)
  end

  uri = node["src"]
  return Vectory::Datauri.new(uri).to_vector if %r{^data:}.match?(uri)

  from_path(uri)
end

.mimetypeObject



13
14
15
# File 'lib/vectory/svg.rb', line 13

def self.mimetype
  "image/svg+xml"
end

Instance Method Details

#to_emfObject



34
35
36
# File 'lib/vectory/svg.rb', line 34

def to_emf
  convert_with_inkscape("--export-type=emf", Emf)
end

#to_epsObject



38
39
40
# File 'lib/vectory/svg.rb', line 38

def to_eps
  convert_with_inkscape("--export-type=eps", Eps)
end

#to_psObject



42
43
44
# File 'lib/vectory/svg.rb', line 42

def to_ps
  convert_with_inkscape("--export-type=ps", Ps)
end