Class: SvgDataPlotterGem::Circle

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_data_plotter/circle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Circle

Returns a new instance of Circle.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#scoreObject (readonly)

Returns the value of attribute score.



3
4
5
# File 'lib/svg_data_plotter/circle.rb', line 3

def score
  @score
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/svg_data_plotter/circle.rb', line 3

def size
  @size
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/svg_data_plotter/circle.rb', line 3

def total
  @total
end

Instance Method Details

#arc_end_lhsObject



57
58
59
# File 'lib/svg_data_plotter/circle.rb', line 57

def arc_end_lhs
  "#{x_co_ord(90)} #{y_co_ord(90)}"
end

#arc_end_rhsObject



53
54
55
# File 'lib/svg_data_plotter/circle.rb', line 53

def arc_end_rhs
  "#{x_co_ord(270)} #{y_co_ord(270)}"
end

#arc_startObject



49
50
51
# File 'lib/svg_data_plotter/circle.rb', line 49

def arc_start
  "#{x_co_ord(90)} #{y_co_ord(90)}"
end

#centerObject



17
18
19
# File 'lib/svg_data_plotter/circle.rb', line 17

def center
  size / 2.0
end

#circumferenceObject



25
26
27
# File 'lib/svg_data_plotter/circle.rb', line 25

def circumference
  radius * 2 * Math::PI
end

#percentageObject



13
14
15
# File 'lib/svg_data_plotter/circle.rb', line 13

def percentage
  (score / total.to_f) * 100
end

#percentage_adjObject



29
30
31
# File 'lib/svg_data_plotter/circle.rb', line 29

def percentage_adj
  (score / total.to_f) * circumference
end

#radians(degrees) ⇒ Object



33
34
35
# File 'lib/svg_data_plotter/circle.rb', line 33

def radians(degrees)
  degrees * Math::PI / 180
end

#radiusObject



21
22
23
# File 'lib/svg_data_plotter/circle.rb', line 21

def radius
  center - 5.0
end

#validation(options, params) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
# 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) ⇒ Object



37
38
39
40
41
# 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) ⇒ Object



43
44
45
46
47
# 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