Class: Victor::CLI::SVGNode

Inherits:
Object
  • Object
show all
Defined in:
lib/victor/cli/svg_node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, layout: nil) ⇒ SVGNode

Initializes with a Nokogiri XML node



24
25
26
27
# File 'lib/victor/cli/svg_node.rb', line 24

def initialize(node, layout: nil)
  @node = node
  @layout = layout || :cli
end

Instance Attribute Details

#layoutObject (readonly)

Returns the value of attribute layout.



9
10
11
# File 'lib/victor/cli/svg_node.rb', line 9

def layout
  @layout
end

#nodeObject (readonly)

Returns the value of attribute node.



9
10
11
# File 'lib/victor/cli/svg_node.rb', line 9

def node
  @node
end

Class Method Details

.load(svg_string, layout: nil) ⇒ Object

Returns a new instance from raw SVG string



17
18
19
20
21
# File 'lib/victor/cli/svg_node.rb', line 17

def self.load(svg_string, layout: nil)
  doc = Nokogiri::XML svg_string
  root = doc.children.last
  new root, layout: layout
end

.load_file(path, layout: nil) ⇒ Object

Returns a new instance from an SVG file



12
13
14
# File 'lib/victor/cli/svg_node.rb', line 12

def self.load_file(path, layout: nil)
  load File.read(path), layout: layout
end

Instance Method Details

#attributesObject

Returns a hash of attributes



51
52
53
# File 'lib/victor/cli/svg_node.rb', line 51

def attributes
  @attributes ||= attributes!
end

#childrenObject

Returns an array of children elements (SVGNode)



61
62
63
# File 'lib/victor/cli/svg_node.rb', line 61

def children
  @children ||= children!
end

#contentObject

Returns the content (body) of the lement



56
57
58
# File 'lib/victor/cli/svg_node.rb', line 56

def content
  @content ||= content!
end

#inspectObject



36
37
38
# File 'lib/victor/cli/svg_node.rb', line 36

def inspect
  "#<#{self.class} name=#{name}, type=#{type}>"
end

#nameObject

Returns the tag name



41
42
43
# File 'lib/victor/cli/svg_node.rb', line 41

def name
  node.name
end

#renderObject

Returns formatted Ruby code



30
31
32
33
34
# File 'lib/victor/cli/svg_node.rb', line 30

def render
  Rufo::Formatter.format ruby_code
rescue Rufo::SyntaxError => e
  raise ruby_code
end

#ruby_codeObject

Returns the ruby code, unformatted



66
67
68
# File 'lib/victor/cli/svg_node.rb', line 66

def ruby_code
  erb erb_template
end

#typeObject

Returns one of our internal types (symbol)



46
47
48
# File 'lib/victor/cli/svg_node.rb', line 46

def type
  @type ||= type!
end