Class: Sus::BeWithin

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/be_within.rb

Defined Under Namespace

Classes: Bounded

Instance Method Summary collapse

Constructor Details

#initialize(tolerance) ⇒ BeWithin

Returns a new instance of BeWithin.



24
25
26
# File 'lib/sus/be_within.rb', line 24

def initialize(tolerance)
	@tolerance = tolerance
end

Instance Method Details

#call(assertions, subject) ⇒ Object



44
45
46
47
48
# File 'lib/sus/be_within.rb', line 44

def call(assertions, subject)
	assertions.nested(self) do |assertions|
		assertions.assert(subject < @tolerance, self)
	end
end

#of(value) ⇒ Object



28
29
30
31
32
# File 'lib/sus/be_within.rb', line 28

def of(value)
	tolerance = @tolerance.abs
	
	return Bounded.new(Range.new(value - tolerance, value + tolerance))
end

#percent_of(value) ⇒ Object



34
35
36
37
38
# File 'lib/sus/be_within.rb', line 34

def percent_of(value)
	tolerance = Rational(@tolerance, 100)
	
	return Bounded.new(Range.new(value - value * tolerance, value + value * tolerance))
end


40
41
42
# File 'lib/sus/be_within.rb', line 40

def print(output)
	output.write("be within ", :variable, @tolerance, :reset)
end