Class: OdataDuty::Filter
- Inherits:
-
Object
- Object
- OdataDuty::Filter
- Defined in:
- lib/odata_duty/filter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filter_string) ⇒ Filter
constructor
A new instance of Filter.
- #operation ⇒ Object
- #property_name ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(filter_string) ⇒ Filter
Returns a new instance of Filter.
56 57 58 |
# File 'lib/odata_duty/filter.rb', line 56 def initialize(filter_string) @property_name, @operation, @value = filter_string.split(nil, 3) end |
Class Method Details
.or?(str) ⇒ Boolean
9 10 11 |
# File 'lib/odata_duty/filter.rb', line 9 def self.or?(str) mask_quoted(str).include?(' or ') end |
.parse(str) ⇒ Object
3 4 5 6 7 |
# File 'lib/odata_duty/filter.rb', line 3 def self.parse(str) validate(str) separator = or?(str) ? ' or ' : ' and ' split_outside_quotes(str, separator).map { |s| new(s) } end |
.validate(str) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/odata_duty/filter.rb', line 13 def self.validate(str) masked = mask_quoted(str) if masked.include?(' and ') && masked.include?(' or ') raise NotYetSupportedError, 'mixed AND/OR not supported' end %w[add sub mul div mod].each do |operator| if masked.include?(" #{operator} ") raise NotYetSupportedError, 'filtering with arithmetic operators not supported' end end return unless masked.include?('(') raise NotYetSupportedError, 'filtering does not support functions or Grouping Operators' end |
Instance Method Details
#operation ⇒ Object
64 65 66 |
# File 'lib/odata_duty/filter.rb', line 64 def operation @operation.to_sym end |
#property_name ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/odata_duty/filter.rb', line 68 def property_name if @property_name.include?('/') raise NotYetSupportedError, 'nested property filtering not supported yet' end @property_name.to_sym end |
#value ⇒ Object
60 61 62 |
# File 'lib/odata_duty/filter.rb', line 60 def value @value.delete_prefix("'").delete_suffix("'") end |