class SvgDataPlotterGem::Circle

Attributes

score[R]
size[R]
total[R]

Public Class Methods

new(options) click to toggle source
# File lib/svg_data_plotter/circle.rb, line 5
def initialize(options)
  validation options, [:score, :total, :size]

  @score = options[:score]
  @total = options[:total]
  @size  = options[:size]
end

Public Instance Methods

arc_end_lhs() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 57
def arc_end_lhs
  "#{x_co_ord(90)} #{y_co_ord(90)}"
end
arc_end_rhs() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 53
def arc_end_rhs
  "#{x_co_ord(270)} #{y_co_ord(270)}"
end
arc_start() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 49
def arc_start
  "#{x_co_ord(90)} #{y_co_ord(90)}"
end
center() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 17
def center
  size / 2.0
end
circumference() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 25
def circumference
  radius * 2 * Math::PI
end
percentage() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 13
def percentage
  (score / total.to_f) * 100
end
percentage_adj() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 29
def percentage_adj
  (score / total.to_f) * circumference
end
radians(degrees) click to toggle source
# File lib/svg_data_plotter/circle.rb, line 33
def radians(degrees)
  degrees * Math::PI / 180
end
radius() click to toggle source
# File lib/svg_data_plotter/circle.rb, line 21
def radius
  center - 5.0
end
validation(options, params) click to toggle source
# File lib/svg_data_plotter/circle.rb, line 61
def validation(options, params)
  raise ArgumentError if options.empty?

  params.each do |key|
    raise ArgumentError unless options.has_key?(key)
  end
end
x_co_ord(angle) click to toggle source
# File lib/svg_data_plotter/circle.rb, line 37
def x_co_ord(angle)
  rad = radians(angle)
  x   = radius * Math.cos(rad)
  center + x
end
y_co_ord(angle) click to toggle source
# File lib/svg_data_plotter/circle.rb, line 43
def y_co_ord(angle)
  rad = radians(angle)
  y   = radius * Math.sin(rad)
  center - y
end