Class: ActiveFacts::Metamodel::ValueRange
- Inherits:
-
Object
- Object
- ActiveFacts::Metamodel::ValueRange
- Defined in:
- lib/activefacts/metamodel/metamodel.rb,
lib/activefacts/metamodel/extensions.rb
Instance Method Summary collapse
-
#effective_maximum ⇒ Object
Note the mismatched return types here:.
- #effective_minimum ⇒ Object
- #includes?(range) ⇒ Boolean
- #inspect ⇒ Object
- #to_s(infinity = true) ⇒ Object
Instance Method Details
#effective_maximum ⇒ Object
Note the mismatched return types here:
1077 1078 1079 |
# File 'lib/activefacts/metamodel/extensions.rb', line 1077 def effective_maximum maximum_bound ? maximum_bound.value : Infinity end |
#effective_minimum ⇒ Object
1081 1082 1083 |
# File 'lib/activefacts/metamodel/extensions.rb', line 1081 def effective_minimum minimum_bound ? minimum_bound.value : -Infinity end |
#includes?(range) ⇒ Boolean
1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/activefacts/metamodel/extensions.rb', line 1085 def includes? range if ValueRange === range range.effective_minimum >= effective_minimum && range.effective_maximum <= effective_maximum # elsif Bound === range # REVISIT: use self.includes?(range.value) with is_literal_string, etc else range >= effective_minimum && range <= effective_maximum end end |
#inspect ⇒ Object
1072 1073 1074 |
# File 'lib/activefacts/metamodel/extensions.rb', line 1072 def inspect to_s end |
#to_s(infinity = true) ⇒ Object
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/activefacts/metamodel/extensions.rb', line 1042 def to_s(infinity = true) min = minimum_bound max = maximum_bound # Open-ended string ranges will fail in Ruby if min = minimum_bound min = min.value if min.is_literal_string min_literal = min.literal.inspect.gsub(/\A"|"\Z/,"'") # Escape string characters else min_literal = min.literal end else min_literal = infinity ? "-Infinity" : "" end if max = maximum_bound max = max.value if max.is_literal_string max_literal = max.literal.inspect.gsub(/\A"|"\Z/,"'") # Escape string characters else max_literal = max.literal end else max_literal = infinity ? "Infinity" : "" end min_literal + (min_literal != (max&&max_literal) ? (".." + max_literal) : "") end |