Class: GeoPattern::SvgImage

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/geo_pattern/svg_image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSvgImage


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

#heightObject

Returns the value of attribute height


11
12
13
# File 'lib/geo_pattern/svg_image.rb', line 11

def height
  @height
end

#widthObject

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

#bodyObject


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_closerObject


39
40
41
# File 'lib/geo_pattern/svg_image.rb', line 39

def svg_closer
  '</svg>'
end

#svg_headerObject


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_sObject


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