svg 0.0.0 → 0.0.1
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.
- data/lib/svg.rb +99 -0
- metadata +7 -1
data/lib/svg.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
#require 'svg'
|
2
|
+
#require 'svg/feature'
|
3
|
+
#require 'svg/circle'
|
4
|
+
|
5
|
+
module Svg
|
6
|
+
|
7
|
+
class RGB
|
8
|
+
def initialize(r=0, g=0, b=0)
|
9
|
+
@red = r
|
10
|
+
@green = g
|
11
|
+
@blue = b
|
12
|
+
end
|
13
|
+
def red
|
14
|
+
@red
|
15
|
+
end
|
16
|
+
def green
|
17
|
+
@green
|
18
|
+
end
|
19
|
+
def blue
|
20
|
+
@blue
|
21
|
+
end
|
22
|
+
def to_s
|
23
|
+
return "rgb(#{@red},#{@green},#{@blue})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Style < String
|
28
|
+
attr_accessor :fill, :stroke, :stroke_width, :fill_opacity, :stroke_opacity
|
29
|
+
def to_s
|
30
|
+
string_val = attr_to_s 'fill', fill
|
31
|
+
string_val += attr_to_s 'stroke', stroke
|
32
|
+
string_val += attr_to_s 'stroke-width', stroke_width
|
33
|
+
string_val += attr_to_s 'fill-opacity', fill_opacity
|
34
|
+
string_val += attr_to_s 'stroke-opacity', stroke_opacity
|
35
|
+
if not string_val.empty?
|
36
|
+
string_val.strip!
|
37
|
+
string_val.chop!
|
38
|
+
end
|
39
|
+
return string_val
|
40
|
+
end
|
41
|
+
def attr_to_s (attr_name, attr_val)
|
42
|
+
return '' if attr_val.nil?
|
43
|
+
" #{attr_name}:#{attr_val};" if not attr_val.to_s.empty?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Feature
|
48
|
+
attr_accessor :stroke, :stroke_width, :fill, :fill_opacity, :stroke_opacity, :style
|
49
|
+
def to_svg
|
50
|
+
'<overrideme/>'
|
51
|
+
end
|
52
|
+
|
53
|
+
def attr_to_s (attr_name, attr_val)
|
54
|
+
return '' if attr_val.nil?
|
55
|
+
" #{attr_name}=\"#{attr_val}\"" if not attr_val.to_s.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class Circle<Feature
|
61
|
+
attr_accessor :center_x, :center_y, :radius
|
62
|
+
def to_svg
|
63
|
+
"<circle cx=\"#{center_x}\" cy=\"#{center_y}\" r=\"#{radius}\" stroke=\"#{stroke}\" stroke-width=\"#{stroke_width}\" fill=\"#{fill}\" />"
|
64
|
+
string_val = "<circle"
|
65
|
+
string_val += attr_to_s 'cx', center_x
|
66
|
+
string_val += attr_to_s 'cy', center_y
|
67
|
+
string_val += attr_to_s 'r', radius
|
68
|
+
string_val += attr_to_s 'stroke', stroke
|
69
|
+
string_val += attr_to_s 'stroke-width', stroke_width
|
70
|
+
string_val += attr_to_s 'fill', fill
|
71
|
+
if not style.nil?
|
72
|
+
string_val += " style=\"#{style.to_s}\""
|
73
|
+
end
|
74
|
+
string_val += "/>"
|
75
|
+
|
76
|
+
return string_val
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Rectangle<Feature
|
81
|
+
attr_accessor :top_x, :top_y, :width, :height
|
82
|
+
def to_svg
|
83
|
+
string_val = "<rect"
|
84
|
+
string_val += attr_to_s 'x', top_x
|
85
|
+
string_val += attr_to_s 'y', top_y
|
86
|
+
string_val += attr_to_s 'width', width
|
87
|
+
string_val += attr_to_s 'height', height
|
88
|
+
if not style.nil?
|
89
|
+
string_val += " style=\"#{style.to_s}\""
|
90
|
+
end
|
91
|
+
string_val += "/>"
|
92
|
+
|
93
|
+
return string_val
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
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.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -31,12 +31,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
+
segments:
|
35
|
+
- 0
|
36
|
+
hash: -4021207685845722209
|
34
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
38
|
none: false
|
36
39
|
requirements:
|
37
40
|
- - ! '>='
|
38
41
|
- !ruby/object:Gem::Version
|
39
42
|
version: '0'
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
hash: -4021207685845722209
|
40
46
|
requirements: []
|
41
47
|
rubyforge_project:
|
42
48
|
rubygems_version: 1.8.24
|