svg 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/svg.rb +34 -15
  2. metadata +21 -5
data/lib/svg.rb CHANGED
@@ -56,15 +56,20 @@ module Svg
56
56
  " #{attr_name}=\"#{attr_val}\"" if not attr_val.to_s.empty?
57
57
  end
58
58
 
59
+ def point_to_s (x_attr_name, y_attr_name, point)
60
+ return '' if point.nil?
61
+ return_val = " #{x_attr_name}=\"#{point.x}\"" if not point.x.to_s.empty?
62
+ return_val + " #{y_attr_name}=\"#{point.y}\"" if not point.y.to_s.empty?
63
+ end
59
64
  end
60
65
 
61
66
  class Circle<Feature
62
- attr_accessor :center_x, :center_y, :radius
67
+ attr_accessor :center, :radius
63
68
  def to_svg
64
- "<circle cx=\"#{center_x}\" cy=\"#{center_y}\" r=\"#{radius}\" stroke=\"#{stroke}\" stroke-width=\"#{stroke_width}\" fill=\"#{fill}\" />"
65
69
  string_val = "<circle"
66
- string_val += attr_to_s 'cx', center_x
67
- string_val += attr_to_s 'cy', center_y
70
+
71
+ string_val += point_to_s 'cx', 'cy', center
72
+
68
73
  string_val += attr_to_s 'r', radius
69
74
  string_val += attr_to_s 'stroke', stroke
70
75
  string_val += attr_to_s 'stroke-width', stroke_width
@@ -79,11 +84,12 @@ module Svg
79
84
  end
80
85
 
81
86
  class Rectangle<Feature
82
- attr_accessor :top_x, :top_y, :radius_x, :radius_y, :width, :height
87
+ attr_accessor :top, :radius_x, :radius_y, :width, :height
83
88
  def to_svg
84
89
  string_val = "<rect"
85
- string_val += attr_to_s 'x', top_x
86
- string_val += attr_to_s 'y', top_y
90
+
91
+ string_val += point_to_s 'x', 'y', top
92
+
87
93
  string_val += attr_to_s 'rx', radius_x
88
94
  string_val += attr_to_s 'ry', radius_y
89
95
  string_val += attr_to_s 'width', width
@@ -99,11 +105,13 @@ module Svg
99
105
  end
100
106
 
101
107
  class Ellipse<Feature
102
- attr_accessor :center_x, :center_y, :radius_x, :radius_y
108
+ attr_accessor :center, :radius_x, :radius_y
103
109
  def to_svg
104
110
  string_val = "<ellipse"
105
- string_val += attr_to_s 'cx', center_x
106
- string_val += attr_to_s 'cy', center_y
111
+
112
+ if not center.nil?
113
+ string_val += point_to_s 'cx', 'cy', center
114
+ end
107
115
  string_val += attr_to_s 'rx', radius_x
108
116
  string_val += attr_to_s 'ry', radius_y
109
117
 
@@ -117,13 +125,11 @@ module Svg
117
125
  end
118
126
 
119
127
  class Line<Feature
120
- attr_accessor :from_x, :from_y, :to_x, :to_y
128
+ attr_accessor :from, :to
121
129
  def to_svg
122
130
  string_val = "<line"
123
- string_val += attr_to_s 'x1', from_x
124
- string_val += attr_to_s 'y1', from_y
125
- string_val += attr_to_s 'x2', to_x
126
- string_val += attr_to_s 'y2', to_y
131
+ string_val += point_to_s 'x1', 'y1', from
132
+ string_val += point_to_s 'x2', 'y2', to
127
133
 
128
134
  if not style.nil?
129
135
  string_val += " style=\"#{style.to_s}\""
@@ -133,4 +139,17 @@ module Svg
133
139
  return string_val
134
140
  end
135
141
  end
142
+
143
+ class Point
144
+ def initialize(x=0, y=0)
145
+ @x = x
146
+ @y = y
147
+ end
148
+ def x
149
+ @x
150
+ end
151
+ def y
152
+ @y
153
+ end
154
+ end
136
155
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-16 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
14
30
  description: Intended to be a gem which will help to build complex Simple Vector Graphics
15
31
  (SVG)
16
32
  email: joelbyler@gmail.com
@@ -33,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
33
49
  version: '0'
34
50
  segments:
35
51
  - 0
36
- hash: -1558949162911032482
52
+ hash: -346562437483372879
37
53
  required_rubygems_version: !ruby/object:Gem::Requirement
38
54
  none: false
39
55
  requirements:
@@ -42,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
58
  version: '0'
43
59
  segments:
44
60
  - 0
45
- hash: -1558949162911032482
61
+ hash: -346562437483372879
46
62
  requirements: []
47
63
  rubyforge_project:
48
64
  rubygems_version: 1.8.24