Class: SVGen::SVG
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(attrs = {}, &block) ⇒ SVG
constructor
A new instance of SVG.
- #method_missing(name, *args) ⇒ Object
Methods included from Nestable
#circle, #group, #line, #path, #rect, #text
Constructor Details
#initialize(attrs = {}, &block) ⇒ SVG
Returns a new instance of SVG.
7 8 9 10 11 |
# File 'lib/svgen/svg.rb', line 7 def initialize(attrs = {}, &block) @children = [] @attrs = attrs block.call(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/svgen/svg.rb', line 20 def method_missing(name, *args) case name.to_s when /^(.+)=$/ super unless value = args.first @attrs.has_key?($1) ? @attrs[$1] = value : @attrs[$1.to_sym] = value else @attrs[name] || @attrs[name.to_sym] end end |
Instance Method Details
#generate ⇒ Object
13 14 15 16 17 18 |
# File 'lib/svgen/svg.rb', line 13 def generate builder = Builder::XmlMarkup.new(indent: 2) builder.svg(@attrs.merge({ xmlns: "http://www.w3.org/2000/svg" })) do |svg| @children.each { |child| child.generate(svg) } end end |