module InterMine::PathQuery::AttributeConstraint
Public Instance Methods
coerce_value(val)
click to toggle source
# File lib/intermine/query.rb 1122 def coerce_value(val) 1123 nums = ["Float", "Double", "float", "double"] 1124 ints = ["Integer", "int"] 1125 bools = ["Boolean", "boolean"] 1126 dataType = @path.elements.last.dataType.split(".").last 1127 coerced = val 1128 if nums.include?(dataType) 1129 if !val.is_a?(Numeric) 1130 coerced = val.to_f 1131 end 1132 end 1133 if ints.include?(dataType) 1134 coerced = val.to_i 1135 end 1136 if bools.include?(dataType) 1137 if !val.is_a?(TrueClass) && !val.is_a?(FalseClass) 1138 if val == 0 or val == "0" or val.downcase == "yes" or val.downcase == "true" or val.downcase == "t" 1139 coerced = true 1140 elsif val == 1 or val == "1" or val.downcase == "no" or val.downcase == "false" or val.downcase == "f" 1141 coerced = false 1142 end 1143 end 1144 end 1145 if coerced == 0 and not val.to_s.start_with?("0") 1146 raise ArgumentError, "cannot coerce #{val} to a #{dataType}" 1147 end 1148 return coerced 1149 end
validate()
click to toggle source
# File lib/intermine/query.rb 1116 def validate 1117 if !@path.elements.last.is_a?(InterMine::Metadata::AttributeDescriptor) 1118 raise ArgumentError, "Attribute constraints must be on attributes, got #{@path}" 1119 end 1120 end
validate_value(val)
click to toggle source
# File lib/intermine/query.rb 1151 def validate_value(val) 1152 nums = ["Float", "Double", "float", "double"] 1153 ints = ["Integer", "int"] 1154 bools = ["Boolean", "boolean"] 1155 dataType = @path.elements.last.dataType.split(".").last 1156 if nums.include?(dataType) 1157 if !val.is_a?(Numeric) 1158 raise ArgumentError, "value #{val} is not numeric for #{@path}" 1159 end 1160 end 1161 if ints.include?(dataType) 1162 val = val.to_i 1163 if !val.is_a?(Integer) 1164 raise ArgumentError, "value #{val} is not an integer for #{@path}" 1165 end 1166 end 1167 if bools.include?(dataType) 1168 if !val.is_a?(TrueClass) && !val.is_a?(FalseClass) 1169 raise ArgumentError, "value #{val} is not a boolean value for #{@path}" 1170 end 1171 end 1172 end