module ImageParadise::Svg::Circle
Constants
- DEFAULT_HEIGHT
#¶ ↑
DEFAULT_HEIGHT
¶ ↑#¶ ↑
- DEFAULT_RADIUS
#¶ ↑
DEFAULT_RADIUS
¶ ↑#¶ ↑
Public Class Methods
create( height_and_width = DEFAULT_HEIGHT, fill_colour = 'red', stroke_width = '3', radius = DEFAULT_RADIUS )
click to toggle source
#¶ ↑
Svg::Circle.create
¶ ↑
This will generate a SVG circle.
A circle has to be synced though as otherwise it is not a circle.
#¶ ↑
# File lib/image_paradise/svg/circle.rb, line 30 def self.create( height_and_width = DEFAULT_HEIGHT, fill_colour = 'red', stroke_width = '3', radius = DEFAULT_RADIUS ) # ======================================================================= # # === Handle Hash given as input to us next # ======================================================================= # if height_and_width.is_a? Hash if height_and_width.has_key? :height height_and_width = height_and_width.delete(:height) # This is ok because width and height are the same. end if height_and_width.has_key? :radius radius = height_and_width.delete(:radius) case radius when :half_default_width radius = DEFAULT_RADIUS.to_f / 2 when :quarter_default_width radius = DEFAULT_RADIUS.to_f / 4 end end if height_and_width.is_a? Hash if height_and_width.has_key? :stroke_width stroke_width = height_and_width.delete(:stroke_width) end if height_and_width.is_a? Hash if height_and_width.has_key? :colour fill_colour = height_and_width.delete(:colour) end if height_and_width.is_a? Hash if height_and_width.respond_to? :empty? height_and_width = DEFAULT_HEIGHT if height_and_width.empty? end end # ======================================================================= # # Convert the various arguments passed to this method into a String. # ======================================================================= # height_and_width = height_and_width.to_s.dup unless height_and_width.is_a? Hash fill_colour = fill_colour.to_s.dup stroke_width = stroke_width.to_s.dup radius = radius.to_i.to_s.dup # ======================================================================= # # === Handle random fill colour # ======================================================================= # if fill_colour == 'random' fill_colour = Colours::HtmlColours.random.dup end _ = Svg.strip( '<svg height="'+height_and_width+'" width="'+height_and_width+'"> <circle cx="50" cy="50" r="'+radius+'" stroke="black" stroke-width="'+stroke_width+'" fill="'+fill_colour+'" />'+ Svg.close_svg )+N _ = _.to_s.dup Svg.add(_) return _ end