Module: Lengthable

Included in:
Headline, ParagraphText
Defined in:
lib/ipsummer/lengthable.rb

Instance Method Summary collapse

Instance Method Details

#default_maxObject



34
35
36
# File 'lib/ipsummer/lengthable.rb', line 34

def default_max
  0
end

#default_minObject



30
31
32
# File 'lib/ipsummer/lengthable.rb', line 30

def default_min
  0
end

#high_limitObject



42
43
44
# File 'lib/ipsummer/lengthable.rb', line 42

def high_limit
  0
end

#lengthObject



2
3
4
# File 'lib/ipsummer/lengthable.rb', line 2

def length
  rand length_min..length_max
end

#length_maxObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ipsummer/lengthable.rb', line 18

def length_max
  if max_no_min?
    max
  elsif min_no_max? && min > default_max
    high_limit
  elsif min_and_max? && max >= min
    max
  else
    default_max
  end
end

#length_minObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ipsummer/lengthable.rb', line 6

def length_min
  if min_no_max?
    min
  elsif max_no_min? && max < default_min
    low_limit
  elsif min_and_max? && min <= max
    min
  else
    default_min
  end
end

#low_limitObject



38
39
40
# File 'lib/ipsummer/lengthable.rb', line 38

def low_limit
  0
end

#maxObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/ipsummer/lengthable.rb', line 62

def max
  raise NotImplementedError, "This #{self.class} cannot respond to:"
end

#max_no_min?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ipsummer/lengthable.rb', line 50

def max_no_min?
  !max.nil? && min.nil?
end

#minObject

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/ipsummer/lengthable.rb', line 58

def min
  raise NotImplementedError, "This #{self.class} cannot respond to:"
end

#min_and_max?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ipsummer/lengthable.rb', line 54

def min_and_max?
  !min.nil? && !max.nil?
end

#min_no_max?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ipsummer/lengthable.rb', line 46

def min_no_max?
  !min.nil? && max.nil?
end