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.
15 16 17 18 19 |
# File 'lib/geo_pattern/svg_image.rb', line 15 def initialize @width = 100 @height = 100 @svg_string = +"" end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
13 14 15 |
# File 'lib/geo_pattern/svg_image.rb', line 13 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
13 14 15 |
# File 'lib/geo_pattern/svg_image.rb', line 13 def width @width end |
Class Method Details
.as_comment(str) ⇒ Object
95 96 97 |
# File 'lib/geo_pattern/svg_image.rb', line 95 def self.as_comment(str) "<!-- #{str} -->" end |
Instance Method Details
#<<(svg) ⇒ Object
53 54 55 |
# File 'lib/geo_pattern/svg_image.rb', line 53 def <<(svg) svg_string << svg.body end |
#<=>(other) ⇒ Object
99 100 101 |
# File 'lib/geo_pattern/svg_image.rb', line 99 def <=>(other) to_s <=> other.to_s end |
#body ⇒ Object
49 50 51 |
# File 'lib/geo_pattern/svg_image.rb', line 49 def body svg_string end |
#circle(cx, cy, r, args = {}) ⇒ Object
61 62 63 |
# File 'lib/geo_pattern/svg_image.rb', line 61 def circle(cx, cy, r, args = {}) svg_string << %(<circle cx="#{cx}" cy="#{cy}" r="#{r}" #{write_args(args)} />) end |
#group(elements, args = {}) ⇒ Object
73 74 75 76 77 |
# File 'lib/geo_pattern/svg_image.rb', line 73 def group(elements, args = {}) svg_string << %(<g #{write_args(args)}>) elements.each { |e| eval e } # rubocop:disable Security/Eval svg_string << %(</g>) end |
#include?(string) ⇒ Boolean
Pattern includes string
33 34 35 |
# File 'lib/geo_pattern/svg_image.rb', line 33 def include?(string) body.include? string end |
#path(str, args = {}) ⇒ Object
65 66 67 |
# File 'lib/geo_pattern/svg_image.rb', line 65 def path(str, args = {}) svg_string << %(<path d="#{str}" #{write_args(args)} />) end |
#polyline(str, args = {}) ⇒ Object
69 70 71 |
# File 'lib/geo_pattern/svg_image.rb', line 69 def polyline(str, args = {}) svg_string << %(<polyline points="#{str}" #{write_args(args)} />) end |
#rect(x, y, width, height, args = {}) ⇒ Object
57 58 59 |
# File 'lib/geo_pattern/svg_image.rb', line 57 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
41 42 43 |
# File 'lib/geo_pattern/svg_image.rb', line 41 def svg_closer "</svg>" end |
#svg_header ⇒ Object
37 38 39 |
# File 'lib/geo_pattern/svg_image.rb', line 37 def svg_header %(<svg xmlns="http://www.w3.org/2000/svg" width="#{@width}" height="#{@height}">) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/geo_pattern/svg_image.rb', line 45 def to_s svg_header + svg_string + svg_closer end |
#write_args(args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/geo_pattern/svg_image.rb', line 79 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 |