Class: SVG::Picture
Overview
#
Picture Class
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#height ⇒ Object
Returns the value of attribute height.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
-
#title ⇒ Object
Returns the value of attribute title.
-
#view_box ⇒ Object
Returns the value of attribute view_box.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #define_style(class_name, style) ⇒ Object
-
#initialize(width, height, view_box = nil) ⇒ Picture
constructor
A new instance of Picture.
- #mime_type ⇒ Object
- #svg ⇒ Object
- #svgz ⇒ Object
- #to_s ⇒ Object
Methods included from ArrayMixin
#<<, #[], #[]=, #clear, #each, #first, #last
Constructor Details
#initialize(width, height, view_box = nil) ⇒ Picture
Returns a new instance of Picture.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-svg/core.rb', line 21 def initialize(width, height, view_box = nil) @width = width @height = height @x = nil @y = nil @view_box = view_box @title = nil @desc = nil @elements = [] @styles = [] @scripts = [] end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def desc @desc end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
35 36 37 |
# File 'lib/ruby-svg/core.rb', line 35 def elements @elements end |
#height ⇒ Object
Returns the value of attribute height.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def height @height end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
35 36 37 |
# File 'lib/ruby-svg/core.rb', line 35 def scripts @scripts end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
35 36 37 |
# File 'lib/ruby-svg/core.rb', line 35 def styles @styles end |
#title ⇒ Object
Returns the value of attribute title.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def title @title end |
#view_box ⇒ Object
Returns the value of attribute view_box.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def view_box @view_box end |
#width ⇒ Object
Returns the value of attribute width.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
36 37 38 |
# File 'lib/ruby-svg/core.rb', line 36 def y @y end |
Instance Method Details
#define_style(class_name, style) ⇒ Object
43 44 45 |
# File 'lib/ruby-svg/core.rb', line 43 def define_style(class_name, style) @styles << DefineStyle.new(class_name, style) end |
#mime_type ⇒ Object
82 83 84 |
# File 'lib/ruby-svg/core.rb', line 82 def mime_type return 'image/svg+xml' end |
#svg ⇒ Object
73 74 75 |
# File 'lib/ruby-svg/core.rb', line 73 def svg return self.to_s end |
#svgz ⇒ Object
77 78 79 80 |
# File 'lib/ruby-svg/core.rb', line 77 def svgz require 'zlib' return Deflate.deflate(self.to_s, Deflate::BEST_COMPRESSION) end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby-svg/core.rb', line 47 def to_s text = %|<?xml version="1.0" standalone="no"?>\n| text << %|<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\n| text << %|<svg width="#{@width}" height="#{@height}"| text << %| viewBox="#{@view_box}"| if @view_box text << %|>\n| @scripts.each { |script| text << script.to_s } unless @styles.empty? text << %|<defs>\n| text << %|<style type="text/css"><![CDATA[\n| text << @styles.collect { |define| define.to_s + "\n" }.join text << %|]]></style>\n| text << %|</defs>\n| end text << %|<title>#{@title}</title>\n| if @title text << %|<desc>#{@desc}</desc>\n| if @desc text << @elements.collect { |element| element.to_s + "\n" }.join text << %|</svg>\n| return text end |