Class: ActiveFacts::Metamodel::PresenceConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/activefacts/metamodel/metamodel.rb,
lib/activefacts/metamodel/extensions.rb

Instance Method Summary collapse

Instance Method Details

#all_constrained_roleObject



1180
1181
1182
# File 'lib/activefacts/metamodel/extensions.rb', line 1180

def all_constrained_role
  role_sequence.all_role_ref.map(&:role)
end

#covers_role(role) ⇒ Object



1176
1177
1178
# File 'lib/activefacts/metamodel/extensions.rb', line 1176

def covers_role role
  role_sequence.all_role_ref.map(&:role).include?(role)
end

#describeObject



1170
1171
1172
1173
1174
# File 'lib/activefacts/metamodel/extensions.rb', line 1170

def describe
  min = min_frequency
  max = max_frequency
  'PresenceConstraint over '+role_sequence.describe + " occurs " + frequency + " time#{(min&&min>1)||(max&&max>1) ? 's' : ''}"
end

#frequencyObject



1160
1161
1162
1163
1164
1165
1166
1167
1168
# File 'lib/activefacts/metamodel/extensions.rb', line 1160

def frequency
  min = min_frequency
  max = max_frequency
  [
      ((min && min > 0 && min != max) ? "at least #{min == 1 ? "one" : min.to_s}" : nil),
      ((max && min != max) ? "at most #{max == 1 ? "one" : max.to_s}" : nil),
      ((max && min == max) ? "#{max == 1 ? "one" : "exactly "+max.to_s}" : nil)
  ].compact * " and "
end