class Render

Constants

Attributes

contents[R]

Public Class Methods

new(elements, width = Config::DUDE_FRAME_SIZE, height = Config::DUDE_FRAME_SIZE) click to toggle source
# File lib/render.rb, line 9
def initialize(elements, width = Config::DUDE_FRAME_SIZE, height = Config::DUDE_FRAME_SIZE)
  code = []
  code << HEADER
  code << %Q[<svg width="#{width}" height="#{height}" style="background:white" xmlns="http://www.w3.org/2000/svg">]
  elements.each { |element| code << hash_to_svg(element) }
  code << %Q[</svg>]

  @contents = code.join("\n")
end

Private Instance Methods

hash_to_svg(hash) click to toggle source
# File lib/render.rb, line 21
def hash_to_svg(hash)
  operator, params = hash.first
  send("svg_#{operator.to_s}".to_sym, params) if defined? operator
end
svg_circle(params) click to toggle source
# File lib/render.rb, line 35
  def svg_circle(params)
    <<~CIRCLE.gsub(/\s+/, " ").strip
      <circle cx="#{params[:cx]}"
      cy="#{params[:cy]}"
      r="#{params[:r]}"
      fill="white" style="stroke:#{params[:color].to_s}; stroke-width:1"/>
    CIRCLE
  end
svg_ellipse(params) click to toggle source
# File lib/render.rb, line 44
  def svg_ellipse(params)
    <<~ELLIPSE.gsub(/\s+/, " ").strip
      <ellipse cx="#{params[:cx]}"
      cy="#{params[:cy]}"
      rx="#{params[:rx]}"
      ry="#{params[:ry]}"
      style="stroke:#{params[:color].to_s}; stroke-width:1" fill="white"/>
    ELLIPSE
  end
svg_line(params) click to toggle source
# File lib/render.rb, line 26
  def svg_line(params)
    <<~LINE.gsub(/\s+/, " ").strip
      <line x1="#{params[:x1]}" y1="#{params[:y1]}"
      x2="#{params[:x2]}"
      y2="#{params[:y2]}"
      style="stroke:#{params[:color]}; stroke-width:1"/>
    LINE
  end
svg_text(params) click to toggle source
# File lib/render.rb, line 54
  def svg_text(params)
    <<~TEXT.gsub(/\s+/, " ").strip
      <text x="#{params[:x]}"
      y="#{params[:y]}"
      font-family="arial" font-size="#{params[:font_size]}"
      fill="#{params[:color].to_s}" style="writing-mode:
      #{params[:orientation].to_s}">#{params[:caption]}</text>
    TEXT
  end