Class: SvgStack
- Inherits:
-
Object
- Object
- SvgStack
- Defined in:
- lib/svgstack.rb
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
Instance Method Summary collapse
- #import(s) ⇒ Object
-
#initialize(data = nil, x: 0, y: 0, width: 150, height: nil) ⇒ SvgStack
constructor
A new instance of SvgStack.
- #render ⇒ Object
- #save(file = 'untitled') ⇒ Object
- #to_svg ⇒ Object
Constructor Details
#initialize(data = nil, x: 0, y: 0, width: 150, height: nil) ⇒ SvgStack
Returns a new instance of SvgStack.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/svgstack.rb', line 29 def initialize(data=nil, x: 0, y: 0, width: 150, height: nil) @x, @y, @width, @height = x, y, width, height @css = " rect { fill: #f6f; } text { fill: blue} " if data then @boxes = data @doc = render() end end |
Instance Attribute Details
#css ⇒ Object
Returns the value of attribute css.
27 28 29 |
# File 'lib/svgstack.rb', line 27 def css @css end |
Instance Method Details
#import(s) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/svgstack.rb', line 50 def import(s) s2 = s.slice(/<\?svgstack [^>]*\?>/) if s2 then attributes = %w(delimiter id schema).inject({}) do |r, keyword| found = s2[/(?<=#{keyword}=['"])[^'"]+/] found ? r.merge(keyword.to_sym => found) : r end end @dx = Dynarex.new s.sub(/svgstack/, 'dynarex') @boxes = @dx.to_h.to_a.reverse @doc = render() end |
#render ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/svgstack.rb', line 69 def render() @height ||= (@boxes.length * 50) + 50 @svg = Victor::SVG.new viewBox: [@x, @y, @width, @height].join(' ') build @boxes end |
#save(file = 'untitled') ⇒ Object
79 80 81 |
# File 'lib/svgstack.rb', line 79 def save(file='untitled') File.write file, @doc end |
#to_svg ⇒ Object
83 84 85 |
# File 'lib/svgstack.rb', line 83 def to_svg() @doc end |