Class: Motion::Meter::ThresholdMeter
- Inherits:
-
NSView
- Object
- NSView
- Motion::Meter::ThresholdMeter
- Defined in:
- lib/motion/meter/threshold_meter.rb
Defined Under Namespace
Classes: Threshold
Instance Attribute Summary collapse
-
#max_value ⇒ Object
Returns the value of attribute max_value.
-
#min_value ⇒ Object
Returns the value of attribute min_value.
-
#thresholds ⇒ Object
Returns the value of attribute thresholds.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_threshold(start, finish, color) ⇒ Object
- #draw_width ⇒ Object
- #drawRect(frame) ⇒ Object
- #range ⇒ Object
Instance Attribute Details
#max_value ⇒ Object
Returns the value of attribute max_value.
4 5 6 |
# File 'lib/motion/meter/threshold_meter.rb', line 4 def max_value @max_value end |
#min_value ⇒ Object
Returns the value of attribute min_value.
4 5 6 |
# File 'lib/motion/meter/threshold_meter.rb', line 4 def min_value @min_value end |
#thresholds ⇒ Object
Returns the value of attribute thresholds.
4 5 6 |
# File 'lib/motion/meter/threshold_meter.rb', line 4 def thresholds @thresholds end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/motion/meter/threshold_meter.rb', line 4 def value @value end |
Instance Method Details
#add_threshold(start, finish, color) ⇒ Object
6 7 8 9 |
# File 'lib/motion/meter/threshold_meter.rb', line 6 def add_threshold(start, finish, color) self.thresholds ||= [] self.thresholds << Threshold.new(start, finish, color) end |
#draw_width ⇒ Object
15 16 17 |
# File 'lib/motion/meter/threshold_meter.rb', line 15 def draw_width (self.bounds.size.width / self.range.to_f) * ((self.value || 0) - self.min_value) end |
#drawRect(frame) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/motion/meter/threshold_meter.rb', line 24 def drawRect(frame) frame.size = [self.draw_width, frame.size.height] if (self.thresholds || []).any? threshold = self.thresholds.detect { |threshold| threshold.start < (self.value || 0) && threshold.finish > (self.value || 0) } color = threshold.color unless threshold.nil? end (color || NSColor.greenColor).setFill NSRectFill(frame) end |
#range ⇒ Object
11 12 13 |
# File 'lib/motion/meter/threshold_meter.rb', line 11 def range self.max_value - self.min_value end |