Class: Uinit::Type::Integer
- Defined in:
- lib/uinit/type/integer.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#negative ⇒ Object
readonly
Returns the value of attribute negative.
-
#positive ⇒ Object
readonly
Returns the value of attribute positive.
-
#zero ⇒ Object
readonly
Returns the value of attribute zero.
Attributes inherited from TypeOf
Instance Method Summary collapse
- #check!(value, depth) ⇒ Object
-
#initialize(min: nil, max: nil, positive: nil, negative: nil, zero: nil) ⇒ Integer
constructor
A new instance of Integer.
- #inspect ⇒ Object
-
#is?(value) ⇒ Boolean
rubocop:disable Metrics/PerceivedComplexity.
-
#options ⇒ Object
rubocop:enable Metrics/PerceivedComplexity.
Methods inherited from TypeOf
Methods inherited from Base
#==, [], from, from?, #is!, #name, #to_s, #trace!, #type_error!
Methods included from Operators
Constructor Details
#initialize(min: nil, max: nil, positive: nil, negative: nil, zero: nil) ⇒ Integer
6 7 8 9 10 11 12 13 14 |
# File 'lib/uinit/type/integer.rb', line 6 def initialize(min: nil, max: nil, positive: nil, negative: nil, zero: nil) super(::Integer) @min = min @max = max @positive = positive @negative = negative @zero = zero end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
16 17 18 |
# File 'lib/uinit/type/integer.rb', line 16 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
16 17 18 |
# File 'lib/uinit/type/integer.rb', line 16 def min @min end |
#negative ⇒ Object (readonly)
Returns the value of attribute negative.
16 17 18 |
# File 'lib/uinit/type/integer.rb', line 16 def negative @negative end |
#positive ⇒ Object (readonly)
Returns the value of attribute positive.
16 17 18 |
# File 'lib/uinit/type/integer.rb', line 16 def positive @positive end |
#zero ⇒ Object (readonly)
Returns the value of attribute zero.
16 17 18 |
# File 'lib/uinit/type/integer.rb', line 16 def zero @zero end |
Instance Method Details
#check!(value, depth) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uinit/type/integer.rb', line 34 def check!(value, depth) super type_error!("Integer too small (minimum #{min})", depth) if min && value < min type_error!("Integer too large (maximum #{max})", depth) if max && value > max type_error!('Integer cannot be positive', depth) if positive == false && value.positive? type_error!('Integer must be positive', depth) if positive == true && value <= 0 type_error!('Integer cannot be negative', depth) if negative == false && value.negative? type_error!('Integer must be negative', depth) if negative == true && value >= 0 type_error!('Integer cannot be zero', depth) if zero == false && value.zero? type_error!('Integer must be zero', depth) if zero == true && !value.zero? value end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/uinit/type/integer.rb', line 54 def inspect "$#{name}[#{options.inspect}]" end |
#is?(value) ⇒ Boolean
rubocop:disable Metrics/PerceivedComplexity
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/uinit/type/integer.rb', line 19 def is?(value) return false unless super return false if min && value < min return false if max && value > max return false if positive == false && value.positive? return false if positive == true && value <= 0 return false if negative == false && value.negative? return false if negative == true && value >= 0 return false if zero == false && value.zero? return false if zero == true && !value.zero? true end |
#options ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
50 51 52 |
# File 'lib/uinit/type/integer.rb', line 50 def { min:, max:, positive:, negative:, zero: }.compact end |