Class: ActiveFacts::Metamodel::Value

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

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Object



1134
1135
1136
# File 'lib/activefacts/metamodel/extensions.rb', line 1134

def !=(other)
  !(self == other)
end

#<(other) ⇒ Object



1148
1149
1150
1151
# File 'lib/activefacts/metamodel/extensions.rb', line 1148

def <(other)
  v = self >= other
  v == nil ? v : !v
end

#<=(other) ⇒ Object



1138
1139
1140
1141
# File 'lib/activefacts/metamodel/extensions.rb', line 1138

def <=(other)
  return true if other == Infinity
  effective_value <= other.effective_value rescue nil
end

#==(other) ⇒ Object



1130
1131
1132
# File 'lib/activefacts/metamodel/extensions.rb', line 1130

def ==(other)
  effective_value == (Value === other ? other.effective_value : other)
end

#>(other) ⇒ Object



1153
1154
1155
1156
# File 'lib/activefacts/metamodel/extensions.rb', line 1153

def >(other)
  v = self >= other
  v == nil ? v : !v
end

#>=(other) ⇒ Object



1143
1144
1145
1146
# File 'lib/activefacts/metamodel/extensions.rb', line 1143

def >=(other)
  return true if other == -Infinity
  effective_value >= other.effective_value rescue nil
end

#effective_valueObject



1126
1127
1128
# File 'lib/activefacts/metamodel/extensions.rb', line 1126

def effective_value
  is_literal_string ? literal : eval(literal)
end

#inspectObject



1122
1123
1124
# File 'lib/activefacts/metamodel/extensions.rb', line 1122

def inspect
  to_s
end

#to_sObject



1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
# File 'lib/activefacts/metamodel/extensions.rb', line 1108

def to_s
  if is_literal_string
    "'"+
    literal.
      inspect.            # Use Ruby's inspect to generate necessary escapes
      gsub(/\A"|"\Z/,''). # Remove surrounding quotes
      gsub(/'/, "\\'") +  # Escape any single quotes
    "'"
  else
    literal
  end +
  (unit ? " " + unit.name : "")
end