class SchmittTrigger
Constants
- VERSION
Attributes
lower_threshold[RW]
output[R]
upper_threshold[RW]
Public Class Methods
new(lower_threshold, upper_threshold)
click to toggle source
# File lib/schmitt_trigger.rb, line 10 def initialize(lower_threshold, upper_threshold) raise LowerThresholdGreaterThanUpperThreshold unless lower_threshold <= upper_threshold raise LowerThresholdSameAsUpperThreshold unless lower_threshold != upper_threshold @lower_threshold = lower_threshold @upper_threshold = upper_threshold end
Public Instance Methods
run(input)
click to toggle source
# File lib/schmitt_trigger.rb, line 17 def run(input) input = [input] unless input.is_a? Array [].tap do |arr| input.each { |i| arr << trigger(i) } end end
Private Instance Methods
trigger(input)
click to toggle source
# File lib/schmitt_trigger.rb, line 26 def trigger(input) @output = lower_threshold if output.nil? case when output == lower_threshold && input >= upper_threshold @output = upper_threshold when output == upper_threshold && input <= lower_threshold @output = lower_threshold end output end