Class: CabezaDeTermo::JsonSpec::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/cabeza-de-termo/json-spec/utilities/range.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max) ⇒ Range

Returns a new instance of Range.



11
12
13
14
15
16
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 11

def initialize(min, max)
	@min = min
	@max = max
	be_closed_at_min
	be_closed_at_max
end

Class Method Details

.new_from(at_min, min, max, at_max) ⇒ Object



4
5
6
7
8
9
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 4

def self.new_from(at_min, min, max, at_max)
	range = self.new(min, max)
	range.be_open_at_min if at_min == '('
	range.be_open_at_max if at_max == ')'
	range
end

Instance Method Details

#be_closed_at_maxObject



24
25
26
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 24

def be_closed_at_max()
	@open_at_max = false
end

#be_closed_at_minObject

Configuring



20
21
22
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 20

def be_closed_at_min()
	@open_at_min = false
end

#be_open_at_maxObject



32
33
34
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 32

def be_open_at_max()
	@open_at_max = true
end

#be_open_at_minObject



28
29
30
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 28

def be_open_at_min()
	@open_at_min = true
end

#includes?(value) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 54

def includes?(value)
	return false if is_open_at_min? && value <= min
	return false if !is_open_at_min? && value < min
	return false if is_open_at_max? && max <= value
	return false if !is_open_at_max? && max < value

	true
end

#is_open_at_max?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 50

def is_open_at_max?()
	@open_at_max
end

#is_open_at_min?Boolean

Asking

Returns:

  • (Boolean)


46
47
48
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 46

def is_open_at_min?()
	@open_at_min
end

#maxObject



40
41
42
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 40

def max()
	@max
end

#minObject



36
37
38
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 36

def min()
	@min
end

#to_sObject

Displaying



65
66
67
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 65

def to_s()
	(is_open_at_min? ? '(' : '[') + min.to_s + ', ' + max.to_s + (is_open_at_max? ? ')' : ']')
end