Class: Nucleo::Models::Concerns::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleo/models/concerns/length.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length, min, max) ⇒ Nucleo::Concerns::Length

Returns an instance of the Length concern domain model

Parameters:

  • length (Integer)
  • min (Integer)
  • max (Integer)


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

#lengthObject (readonly)

Returns the value of attribute length.



5
6
7
# File 'lib/nucleo/models/concerns/length.rb', line 5

def length
  @length
end

#maxObject (readonly)

Returns the value of attribute max.



5
6
7
# File 'lib/nucleo/models/concerns/length.rb', line 5

def max
  @max
end

#minObject (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


44
45
46
# File 'lib/nucleo/models/concerns/length.rb', line 44

def too_long?
  (self.max? && (self.length > self.max))
end

#too_long_lengthInteger

Returns the too long length

Returns:

  • (Integer)


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

Returns:

  • (Boolean)


30
31
32
# File 'lib/nucleo/models/concerns/length.rb', line 30

def too_short?
  (self.length <= self.min)
end

#too_short_lengthInteger

Returns the too short length

Returns:

  • (Integer)


37
38
39
# File 'lib/nucleo/models/concerns/length.rb', line 37

def too_short_length
  (self.min - self.length)
end