Class: SvgStack

Inherits:
Object
  • Object
show all
Defined in:
lib/svgstack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil, x: 0, y: 0, width: 150, height: nil) ⇒ SvgStack

Returns a new instance of SvgStack.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/svgstack.rb', line 28

def initialize(data=nil, x: 0,  y: 0, width: 150, height: nil)

  boxes = data if data.is_a? Array
  
  height ||= (boxes.length * 50) + 50    

  @svg = Victor::SVG.new viewBox: [x, y, width, height].join(' ')
  @boxwidth = width
  build boxes
  
  @css = "
  rect {
    fill: #f6f;
  }

  text { fill: blue}
"

end

Instance Attribute Details

#cssObject

Returns the value of attribute css.



26
27
28
# File 'lib/svgstack.rb', line 26

def css
  @css
end

Instance Method Details

#save(file = 'untitled') ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/svgstack.rb', line 48

def save(file='untitled')
  
  @svg.save file
  
  #inject the css    
  
  s = File.read file
  s2 = s.lines.insert 7, css_code()
  File.write file, s2.join
end