Commit e0ba34d
Changed files (2)
lib
scale
spec
lib/scale/svg.rb
@@ -2,9 +2,19 @@ require 'nokogiri'
module Scale
class SVG
+ attr_accessor :width, :height
+
def to_xml
builder = Nokogiri::XML::Builder.new do |xml|
- xml.svg(version: "1.1", baseProfile: "full", xmlns: "http://www.w3.org/2000/svg") do
+ attributes = {
+ version: "1.1",
+ baseProfile: "full",
+ xmlns: "http://www.w3.org/2000/svg",
+ }
+ attributes[:width] = width unless width.nil?
+ attributes[:height] = height unless height.nil?
+
+ xml.svg(attributes) do
end
end
builder.to_xml
spec/svg_spec.rb
@@ -2,11 +2,28 @@ describe Scale::SVG do
subject { Scale::SVG.new }
it 'produces and empty xml document' do
- result = subject.to_xml
expected = <<-XML
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg\" version="1.1" baseProfile="full"/>
XML
- expect(result).to eql(expected)
+ expect(subject.to_xml).to eql(expected)
+ end
+
+ it 'applies a width' do
+ subject.width = rand(1000)
+ expected = <<-XML
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg\" version="1.1" baseProfile="full" width="#{subject.width}"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
+
+ it 'applies a height' do
+ subject.height = rand(1000)
+ expected = <<-XML
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg\" version="1.1" baseProfile="full" height="#{subject.height}"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
end
end