Class: SvgDataPlotterGem::Gauge
- Inherits:
-
Object
- Object
- SvgDataPlotterGem::Gauge
- Defined in:
- lib/svg_data_plotter/gauge.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 ⇒ Object
- #arc_start ⇒ Object
- #center ⇒ Object
- #height ⇒ Object
-
#initialize(options) ⇒ Gauge
constructor
A new instance of Gauge.
- #offset ⇒ Object
- #percentage ⇒ Object
- #percentage_adj ⇒ Object
- #radians(degrees) ⇒ Object
- #radius ⇒ Object
- #semi_circle ⇒ Object
- #validation(options, params) ⇒ Object
- #x_co_ord(angle) ⇒ Object
- #y_co_ord(angle) ⇒ Object
Constructor Details
#initialize(options) ⇒ Gauge
Returns a new instance of Gauge.
5 6 7 8 9 10 11 |
# File 'lib/svg_data_plotter/gauge.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/gauge.rb', line 3 def score @score end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/svg_data_plotter/gauge.rb', line 3 def size @size end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/svg_data_plotter/gauge.rb', line 3 def total @total end |
Instance Method Details
#arc_end ⇒ Object
61 62 63 |
# File 'lib/svg_data_plotter/gauge.rb', line 61 def arc_end "#{x_co_ord(180)} #{y_co_ord(180)}" end |
#arc_start ⇒ Object
57 58 59 |
# File 'lib/svg_data_plotter/gauge.rb', line 57 def arc_start "#{x_co_ord(0)} #{y_co_ord(0)}" end |
#center ⇒ Object
21 22 23 |
# File 'lib/svg_data_plotter/gauge.rb', line 21 def center size / 2.0 end |
#height ⇒ Object
13 14 15 |
# File 'lib/svg_data_plotter/gauge.rb', line 13 def height (size / 2.0) + 15.0 end |
#offset ⇒ Object
37 38 39 |
# File 'lib/svg_data_plotter/gauge.rb', line 37 def offset percentage_adj - semi_circle end |
#percentage ⇒ Object
17 18 19 |
# File 'lib/svg_data_plotter/gauge.rb', line 17 def percentage (score / total.to_f) * 100 end |
#percentage_adj ⇒ Object
33 34 35 |
# File 'lib/svg_data_plotter/gauge.rb', line 33 def percentage_adj (score / total.to_f) * semi_circle end |
#radians(degrees) ⇒ Object
41 42 43 |
# File 'lib/svg_data_plotter/gauge.rb', line 41 def radians(degrees) degrees * Math::PI / 180 end |
#radius ⇒ Object
25 26 27 |
# File 'lib/svg_data_plotter/gauge.rb', line 25 def radius center - 10.0 end |
#semi_circle ⇒ Object
29 30 31 |
# File 'lib/svg_data_plotter/gauge.rb', line 29 def semi_circle radius * Math::PI end |
#validation(options, params) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/svg_data_plotter/gauge.rb', line 65 def validation(, params) raise ArgumentError if .empty? params.each do |key| raise ArgumentError unless .has_key?(key) end end |
#x_co_ord(angle) ⇒ Object
45 46 47 48 49 |
# File 'lib/svg_data_plotter/gauge.rb', line 45 def x_co_ord(angle) rad = radians(angle) x = radius * Math.cos(rad) center + x end |
#y_co_ord(angle) ⇒ Object
51 52 53 54 55 |
# File 'lib/svg_data_plotter/gauge.rb', line 51 def y_co_ord(angle) rad = radians(angle) y = radius * Math.sin(rad) center - y end |