Class: Nucleo::Models::Concerns::Length
- Inherits:
-
Object
- Object
- Nucleo::Models::Concerns::Length
- Defined in:
- lib/nucleo/models/concerns/length.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
-
#initialize(length, min, max) ⇒ Nucleo::Concerns::Length
constructor
Returns an instance of the Length concern domain model.
-
#max? ⇒ Boolean
Returns true if there is a max.
-
#too_long? ⇒ Boolean
Returns true if too long.
-
#too_long_length ⇒ Integer
Returns the too long length.
-
#too_short? ⇒ Boolean
Returns true if too short.
-
#too_short_length ⇒ Integer
Returns the too short length.
Constructor Details
#initialize(length, min, max) ⇒ Nucleo::Concerns::Length
Returns an instance of the Length concern domain model
14 15 16 17 18 |
# File 'lib/nucleo/models/concerns/length.rb', line 14 def initialize(length, min, max) @length = length.to_i @min = min.to_i @max = max.to_i end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
5 6 7 |
# File 'lib/nucleo/models/concerns/length.rb', line 5 def length @length end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
5 6 7 |
# File 'lib/nucleo/models/concerns/length.rb', line 5 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
5 6 7 |
# File 'lib/nucleo/models/concerns/length.rb', line 5 def min @min end |
Instance Method Details
#max? ⇒ Boolean
Returns true if there is a max
23 24 25 |
# File 'lib/nucleo/models/concerns/length.rb', line 23 def max? (self.max > 0) end |
#too_long? ⇒ Boolean
Returns true if too long
44 45 46 |
# File 'lib/nucleo/models/concerns/length.rb', line 44 def too_long? (self.max? && (self.length > self.max)) end |
#too_long_length ⇒ Integer
Returns the too long length
51 52 53 |
# File 'lib/nucleo/models/concerns/length.rb', line 51 def too_long_length (self.length - self.max) end |
#too_short? ⇒ Boolean
Returns true if too short
30 31 32 |
# File 'lib/nucleo/models/concerns/length.rb', line 30 def too_short? (self.length <= self.min) end |
#too_short_length ⇒ Integer
Returns the too short length
37 38 39 |
# File 'lib/nucleo/models/concerns/length.rb', line 37 def too_short_length (self.min - self.length) end |