Class: Victor::CLI::SVGNode
- Inherits:
-
Object
- Object
- Victor::CLI::SVGNode
- Defined in:
- lib/victor/cli/svg_node.rb
Instance Attribute Summary collapse
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
-
.load(svg_string, layout: nil) ⇒ Object
Returns a new instance from raw SVG string.
-
.load_file(path, layout: nil) ⇒ Object
Returns a new instance from an SVG file.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns a hash of attributes.
-
#children ⇒ Object
Returns an array of children elements (SVGNode).
-
#content ⇒ Object
Returns the content (body) of the lement.
-
#initialize(node, layout: nil) ⇒ SVGNode
constructor
Initializes with a Nokogiri XML node.
- #inspect ⇒ Object
-
#name ⇒ Object
Returns the tag name.
-
#render ⇒ Object
Returns formatted Ruby code.
-
#ruby_code ⇒ Object
Returns the ruby code, unformatted.
-
#type ⇒ Object
Returns one of our internal types (symbol).
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
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
9 10 11 |
# File 'lib/victor/cli/svg_node.rb', line 9 def layout @layout end |
#node ⇒ Object (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
#attributes ⇒ Object
Returns a hash of attributes
51 52 53 |
# File 'lib/victor/cli/svg_node.rb', line 51 def attributes @attributes ||= attributes! end |
#children ⇒ Object
Returns an array of children elements (SVGNode)
61 62 63 |
# File 'lib/victor/cli/svg_node.rb', line 61 def children @children ||= children! end |
#content ⇒ Object
Returns the content (body) of the lement
56 57 58 |
# File 'lib/victor/cli/svg_node.rb', line 56 def content @content ||= content! end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/victor/cli/svg_node.rb', line 36 def inspect "#<#{self.class} name=#{name}, type=#{type}>" end |
#name ⇒ Object
Returns the tag name
41 42 43 |
# File 'lib/victor/cli/svg_node.rb', line 41 def name node.name end |
#render ⇒ Object
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_code ⇒ Object
Returns the ruby code, unformatted
66 67 68 |
# File 'lib/victor/cli/svg_node.rb', line 66 def ruby_code erb erb_template end |
#type ⇒ Object
Returns one of our internal types (symbol)
46 47 48 |
# File 'lib/victor/cli/svg_node.rb', line 46 def type @type ||= type! end |