class Philtre::PredicateSplitter
This is to split things like birth_year_gt into
- birth_year (the field) - gt (the predicate)
Yes, there are side effects.
is provided so it can be used in case statements¶ ↑
(which doesn't really work cos they're backwards).
Attributes
key[R]
value[R]
Public Class Methods
new( key, value )
click to toggle source
# File lib/philtre/predicate_splitter.rb, line 11 def initialize( key, value ) @key, @value = key, value end
Public Instance Methods
field()
click to toggle source
return name if the split was successful, or fall back to key which is handy when none of the predicates match and so key is probably just a field name.
# File lib/philtre/predicate_splitter.rb, line 31 def field (@field || @key).andand.to_sym end
op()
click to toggle source
the operator, or predicate
# File lib/philtre/predicate_splitter.rb, line 36 def op @op.andand.to_sym end
split_key( suffix )
click to toggle source
split suffix from the key and store the two values as name and op return truthy if successful
# File lib/philtre/predicate_splitter.rb, line 19 def split_key( suffix ) rv = @key =~ /\A(?:(.*?)_)?(#{suffix})\z/ @field, @op = $1, $2 rv end