Module: Lengthable

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

Instance Method Summary collapse

Instance Method Details

#default_maxObject



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

def default_max
  0
end

#default_minObject



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

def default_min
  0
end

#high_limitObject



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

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ipsummer/lengthable.rb', line 26

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

#length_minObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ipsummer/lengthable.rb', line 6

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

#low_limitObject



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

def low_limit
  0
end

#maxObject

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/ipsummer/lengthable.rb', line 78

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

#max_no_min?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ipsummer/lengthable.rb', line 66

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

#minObject

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/ipsummer/lengthable.rb', line 74

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

#min_and_max?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ipsummer/lengthable.rb', line 70

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

#min_no_max?Boolean

Returns:

  • (Boolean)


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

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