Class: SvgDataPlotterGem::Circle
- Inherits:
-
Object
- Object
- SvgDataPlotterGem::Circle
- Defined in:
- lib/svg_data_plotter/circle.rb
Instance Attribute Summary collapse
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #arc_end_lhs ⇒ Object
- #arc_end_rhs ⇒ Object
- #arc_start ⇒ Object
- #center ⇒ Object
- #circumference ⇒ Object
-
#initialize(options) ⇒ Circle
constructor
A new instance of Circle.
- #percentage ⇒ Object
- #percentage_adj ⇒ Object
- #radians(degrees) ⇒ Object
- #radius ⇒ Object
- #validation(options, params) ⇒ Object
- #x_co_ord(angle) ⇒ Object
- #y_co_ord(angle) ⇒ Object
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() validation , [:score, :total, :size] @score = [:score] @total = [:total] @size = [:size] end |
Instance Attribute Details
#score ⇒ Object (readonly)
Returns the value of attribute score.
3 4 5 |
# File 'lib/svg_data_plotter/circle.rb', line 3 def score @score end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/svg_data_plotter/circle.rb', line 3 def size @size end |
#total ⇒ Object (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_lhs ⇒ Object
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_rhs ⇒ Object
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_start ⇒ Object
49 50 51 |
# File 'lib/svg_data_plotter/circle.rb', line 49 def arc_start "#{x_co_ord(90)} #{y_co_ord(90)}" end |
#center ⇒ Object
17 18 19 |
# File 'lib/svg_data_plotter/circle.rb', line 17 def center size / 2.0 end |
#circumference ⇒ Object
25 26 27 |
# File 'lib/svg_data_plotter/circle.rb', line 25 def circumference radius * 2 * Math::PI end |
#percentage ⇒ Object
13 14 15 |
# File 'lib/svg_data_plotter/circle.rb', line 13 def percentage (score / total.to_f) * 100 end |
#percentage_adj ⇒ Object
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 |
#radius ⇒ Object
21 22 23 |
# File 'lib/svg_data_plotter/circle.rb', line 21 def radius center - 5.0 end |
#validation(options, params) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/svg_data_plotter/circle.rb', line 61 def validation(, params) raise ArgumentError if .empty? params.each do |key| raise ArgumentError unless .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 |