Class: GeoPattern::SvgImage
- Inherits:
-
Object
- Object
- GeoPattern::SvgImage
- Includes:
- Comparable
- Defined in:
- lib/geo_pattern/svg_image.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(svg) ⇒ Object
- #<=>(other) ⇒ Object
- #body ⇒ Object
- #circle(cx, cy, r, args = {}) ⇒ Object
- #group(elements, args = {}) ⇒ Object
-
#include?(string) ⇒ Boolean
Pattern includes string.
-
#initialize ⇒ SvgImage
constructor
A new instance of SvgImage.
- #path(str, args = {}) ⇒ Object
- #polyline(str, args = {}) ⇒ Object
- #rect(x, y, width, height, args = {}) ⇒ Object
- #svg_closer ⇒ Object
- #svg_header ⇒ Object
- #to_s ⇒ Object
- #write_args(args) ⇒ Object
Constructor Details
#initialize ⇒ SvgImage
Returns a new instance of SvgImage.
13 14 15 16 17 |
# File 'lib/geo_pattern/svg_image.rb', line 13 def initialize @width = 100 @height = 100 @svg_string = '' end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/geo_pattern/svg_image.rb', line 11 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/geo_pattern/svg_image.rb', line 11 def width @width end |
Class Method Details
.as_comment(str) ⇒ Object
93 94 95 |
# File 'lib/geo_pattern/svg_image.rb', line 93 def self.as_comment(str) "<!-- #{str} -->" end |
Instance Method Details
#<<(svg) ⇒ Object
51 52 53 |
# File 'lib/geo_pattern/svg_image.rb', line 51 def <<(svg) svg_string << svg.body end |
#<=>(other) ⇒ Object
97 98 99 |
# File 'lib/geo_pattern/svg_image.rb', line 97 def <=>(other) to_s <=> other.to_s end |
#body ⇒ Object
47 48 49 |
# File 'lib/geo_pattern/svg_image.rb', line 47 def body svg_string end |
#circle(cx, cy, r, args = {}) ⇒ Object
59 60 61 |
# File 'lib/geo_pattern/svg_image.rb', line 59 def circle(cx, cy, r, args = {}) svg_string << %(<circle cx="#{cx}" cy="#{cy}" r="#{r}" #{write_args(args)} />) end |
#group(elements, args = {}) ⇒ Object
71 72 73 74 75 |
# File 'lib/geo_pattern/svg_image.rb', line 71 def group(elements, args = {}) svg_string << %(<g #{write_args(args)}>) elements.each { |e| eval e } svg_string << %(</g>) end |
#include?(string) ⇒ Boolean
Pattern includes string
31 32 33 |
# File 'lib/geo_pattern/svg_image.rb', line 31 def include?(string) body.include? string end |
#path(str, args = {}) ⇒ Object
63 64 65 |
# File 'lib/geo_pattern/svg_image.rb', line 63 def path(str, args = {}) svg_string << %(<path d="#{str}" #{write_args(args)} />) end |
#polyline(str, args = {}) ⇒ Object
67 68 69 |
# File 'lib/geo_pattern/svg_image.rb', line 67 def polyline(str, args = {}) svg_string << %(<polyline points="#{str}" #{write_args(args)} />) end |
#rect(x, y, width, height, args = {}) ⇒ Object
55 56 57 |
# File 'lib/geo_pattern/svg_image.rb', line 55 def rect(x, y, width, height, args = {}) svg_string << %(<rect x="#{x}" y="#{y}" width="#{width}" height="#{height}" #{write_args(args)} />) end |
#svg_closer ⇒ Object
39 40 41 |
# File 'lib/geo_pattern/svg_image.rb', line 39 def svg_closer '</svg>' end |
#svg_header ⇒ Object
35 36 37 |
# File 'lib/geo_pattern/svg_image.rb', line 35 def svg_header %(<svg xmlns="http://www.w3.org/2000/svg" width="#{@width}" height="#{@height}">) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/geo_pattern/svg_image.rb', line 43 def to_s svg_header + svg_string + svg_closer end |
#write_args(args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/geo_pattern/svg_image.rb', line 77 def write_args(args) str = '' args.each do|key, value| if value.is_a?(Hash) str << %(#{key}=") value.each do|k, v| str << %(#{k}:#{v};) end str << %(" ) else str << %(#{key}="#{value}" ) end end str end |