Class: CabezaDeTermo::JsonSpec::Range
- Inherits:
-
Object
- Object
- CabezaDeTermo::JsonSpec::Range
- Defined in:
- lib/cabeza-de-termo/json-spec/utilities/range.rb
Class Method Summary collapse
Instance Method Summary collapse
- #be_closed_at_max ⇒ Object
-
#be_closed_at_min ⇒ Object
Configuring.
- #be_open_at_max ⇒ Object
- #be_open_at_min ⇒ Object
- #includes?(value) ⇒ Boolean
-
#initialize(min, max) ⇒ Range
constructor
A new instance of Range.
- #is_open_at_max? ⇒ Boolean
-
#is_open_at_min? ⇒ Boolean
Asking.
- #max ⇒ Object
- #min ⇒ Object
-
#to_s ⇒ Object
Displaying.
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_max ⇒ Object
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_min ⇒ Object
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_max ⇒ Object
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_min ⇒ Object
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
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
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
46 47 48 |
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 46 def is_open_at_min?() @open_at_min end |
#max ⇒ Object
40 41 42 |
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 40 def max() @max end |
#min ⇒ Object
36 37 38 |
# File 'lib/cabeza-de-termo/json-spec/utilities/range.rb', line 36 def min() @min end |
#to_s ⇒ Object
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 |