Class: GeoPattern::SVG
- Inherits:
-
Object
- Object
- GeoPattern::SVG
- Includes:
- Comparable
- Defined in:
- lib/geo_pattern/svg.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #circle(cx, cy, r, args = {}) ⇒ Object
- #group(elements, args = {}) ⇒ Object
-
#initialize ⇒ SVG
constructor
A new instance of SVG.
- #path(str, args = {}) ⇒ Object
- #polyline(str, args = {}) ⇒ Object
- #rect(x, y, width, height, args = {}) ⇒ Object
- #set_height(height) ⇒ Object
- #set_width(width) ⇒ Object
- #svg_closer ⇒ Object
- #svg_header ⇒ Object
- #to_s ⇒ Object
- #write_args(args) ⇒ Object
Constructor Details
#initialize ⇒ SVG
Returns a new instance of SVG.
5 6 7 8 9 |
# File 'lib/geo_pattern/svg.rb', line 5 def initialize @width = 100 @height = 100 @svg_string = "" end |
Class Method Details
.as_comment(str) ⇒ Object
69 70 71 |
# File 'lib/geo_pattern/svg.rb', line 69 def self.as_comment(str) "<!-- #{str} -->" end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/geo_pattern/svg.rb', line 73 def <=>(other) to_s <=> other.to_s end |
#circle(cx, cy, r, args = {}) ⇒ Object
35 36 37 |
# File 'lib/geo_pattern/svg.rb', line 35 def circle(cx, cy, r, args={}) @svg_string << %Q{<circle cx="#{cx}" cy="#{cy}" r="#{r}" #{write_args(args)} />} end |
#group(elements, args = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/geo_pattern/svg.rb', line 47 def group(elements, args={}) @svg_string << %Q{<g #{write_args(args)}>} elements.each {|e| eval e} @svg_string << %Q{</g>} end |
#path(str, args = {}) ⇒ Object
39 40 41 |
# File 'lib/geo_pattern/svg.rb', line 39 def path(str, args={}) @svg_string << %Q{<path d="#{str}" #{write_args(args)} />} end |
#polyline(str, args = {}) ⇒ Object
43 44 45 |
# File 'lib/geo_pattern/svg.rb', line 43 def polyline(str, args={}) @svg_string << %Q{<polyline points="#{str}" #{write_args(args)} />} end |
#rect(x, y, width, height, args = {}) ⇒ Object
31 32 33 |
# File 'lib/geo_pattern/svg.rb', line 31 def rect(x, y, width, height, args={}) @svg_string << %Q{<rect x="#{x}" y="#{y}" width="#{width}" height="#{height}" #{write_args(args)} />} end |
#set_height(height) ⇒ Object
15 16 17 |
# File 'lib/geo_pattern/svg.rb', line 15 def set_height(height) @height = height.floor end |
#set_width(width) ⇒ Object
11 12 13 |
# File 'lib/geo_pattern/svg.rb', line 11 def set_width(width) @width = width.floor end |
#svg_closer ⇒ Object
23 24 25 |
# File 'lib/geo_pattern/svg.rb', line 23 def svg_closer "</svg>" end |
#svg_header ⇒ Object
19 20 21 |
# File 'lib/geo_pattern/svg.rb', line 19 def svg_header %Q{<svg xmlns="http://www.w3.org/2000/svg" width="#{@width}" height="#{@height}">} end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/geo_pattern/svg.rb', line 27 def to_s svg_header + @svg_string + svg_closer end |
#write_args(args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/geo_pattern/svg.rb', line 53 def write_args(args) str = "" args.each {|key, value| if value.is_a?(Hash) str << %Q{#{key}="} value.each {|k, v| str << %Q{#{k}:#{v};} } str << %Q{" } else str << %Q{#{key}="#{value}" } end } str end |