diff options
| author | mo khan <mo@mokhan.ca> | 2015-04-08 15:54:38 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-04-08 15:54:38 -0600 |
| commit | 21bdd0a70c641745e95f508b429e591bda8297ed (patch) | |
| tree | 68c1be0e34f3713413a7499595bb6718a27ecb7b | |
| parent | c7363e63f3d6d60debe3721cecf3354d1904405d (diff) | |
convert snake case attributes to hyphen case.
| -rw-r--r-- | lib/scale/node.rb | 6 | ||||
| -rw-r--r-- | lib/scale/shapes/rectangle.rb | 3 | ||||
| -rw-r--r-- | spec/node_spec.rb | 10 | ||||
| -rw-r--r-- | spec/shapes/path_spec.rb | 10 |
4 files changed, 24 insertions, 5 deletions
diff --git a/lib/scale/node.rb b/lib/scale/node.rb index c71d589..21fd7da 100644 --- a/lib/scale/node.rb +++ b/lib/scale/node.rb @@ -36,7 +36,11 @@ module Scale end def xml_attributes - attributes.delete_if { |key, value| value.nil? } + attributes.inject({}) do |memo, (key, value)| + new_key = key.to_s.gsub(/\_/, "-").to_sym + memo[new_key] = value unless value.nil? + memo + end end private diff --git a/lib/scale/shapes/rectangle.rb b/lib/scale/shapes/rectangle.rb index 8aaa01e..a51b993 100644 --- a/lib/scale/shapes/rectangle.rb +++ b/lib/scale/shapes/rectangle.rb @@ -4,6 +4,9 @@ module Scale attribute :width, String attribute :height, String attribute :fill, String + attribute :fill_opactiy, String + attribute :stroke, String + attribute :stroke_opacity, String attribute :x, Integer attribute :y, Integer attribute :rx, Integer diff --git a/spec/node_spec.rb b/spec/node_spec.rb index 12c69c7..c277dd6 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -3,6 +3,7 @@ describe Scale::Node do include Scale::Node attribute :x, Integer attribute :y, Integer + attribute :fill_opacity, Float def xml_tag :fake @@ -42,5 +43,14 @@ describe Scale::Node do XML expect(subject.to_xml).to eql(expected) end + + it 'replaces underscores in attribute names' do + subject.fill_opacity = 0.5 + expected = <<-XML +<?xml version="1.0"?> +<fake fill-opacity="0.5"/> + XML + expect(subject.to_xml).to eql(expected) + end end end diff --git a/spec/shapes/path_spec.rb b/spec/shapes/path_spec.rb index f6df8c0..58d3810 100644 --- a/spec/shapes/path_spec.rb +++ b/spec/shapes/path_spec.rb @@ -23,8 +23,11 @@ describe Scale::Path do end describe "#horizontal" do - it 'draws a horizontal line' do + before :each do subject.move_to(x: 10, y: 10) + end + + it 'draws a horizontal line' do subject.horizontal(90) expected = <<-XML <?xml version="1.0"?> @@ -34,7 +37,6 @@ describe Scale::Path do end it 'moves horizontally using relative position' do - subject.move_to(x: 10, y: 10) subject.horizontal(90, relative: true) expected = <<-XML <?xml version="1.0"?> @@ -44,7 +46,7 @@ describe Scale::Path do end end - describe "#vertial" do + describe "#vertical" do before :each do subject.move_to(x: 10, y: 10) end @@ -88,7 +90,7 @@ describe Scale::Path do subject.vertical(90) subject.horizontal(10) subject.line_to(x: 10, y: 10) - + expected = <<-XML <?xml version="1.0"?> <path d="M10 10 H 90 V 90 H 10 L 10 10"/> |
