Class: Motion::Meter::ThresholdMeter

Inherits:
NSView
  • Object
show all
Defined in:
lib/motion/meter/threshold_meter.rb

Defined Under Namespace

Classes: Threshold

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_valueObject

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_valueObject

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

#thresholdsObject

Returns the value of attribute thresholds.



4
5
6
# File 'lib/motion/meter/threshold_meter.rb', line 4

def thresholds
  @thresholds
end

#valueObject

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_widthObject



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

#rangeObject



11
12
13
# File 'lib/motion/meter/threshold_meter.rb', line 11

def range
  self.max_value - self.min_value
end