Class: SData::Predicate
- Inherits:
-
Struct
- Object
- Struct
- SData::Predicate
- Defined in:
- lib/s_data/predicate.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#relation ⇒ Object
Returns the value of attribute relation.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field
2 3 4 |
# File 'lib/s_data/predicate.rb', line 2 def field @field end |
#relation ⇒ Object
Returns the value of attribute relation
2 3 4 |
# File 'lib/s_data/predicate.rb', line 2 def relation @relation end |
#value ⇒ Object
Returns the value of attribute value
2 3 4 |
# File 'lib/s_data/predicate.rb', line 2 def value @value end |
Class Method Details
.parse(fields_map, predicate_string) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/s_data/predicate.rb', line 3 def self.parse(fields_map, predicate_string) # Gotcha on Rightscale that escaped + before it hits controller, but doesn't escape other special chars! escaped_predicate_string = CGI::unescape(predicate_string.gsub('+', '%2B')) match_data = escaped_predicate_string.match(/(\w+)\s(gt|lt|eq|ne|lteq|gteq)\s('?.+'?|'')/) || [] canonical_field_name = match_data[1].underscore.to_sym unless match_data[1].nil? self.new fields_map[canonical_field_name], match_data[2], strip_quotes(match_data[3]) end |
.strip_quotes(value) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/s_data/predicate.rb', line 12 def self.strip_quotes(value) return value unless value.is_a?(String) value = value.gsub("%27", "'") return value unless value =~ /'.*?'/ return value[1,value.length-2] end |
Instance Method Details
#to_conditions ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/s_data/predicate.rb', line 19 def to_conditions if valid? ConditionsBuilder.build_conditions field, relation.to_sym, value else raise Sage::BusinessLogic::Exception::IncompatibleDataException, "Invalid predicate string" end end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/s_data/predicate.rb', line 27 def valid? field && relation && value end |