Class: Philtre::PredicateSplitter
- Inherits:
-
Object
- Object
- Philtre::PredicateSplitter
- Defined in:
- lib/philtre/predicate_splitter.rb
Overview
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).
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#field ⇒ Object
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.
-
#initialize(key, value) ⇒ PredicateSplitter
constructor
A new instance of PredicateSplitter.
-
#op ⇒ Object
the operator, or predicate.
-
#split_key(suffix) ⇒ Object
(also: #===, #=~)
split suffix from the key and store the two values as name and op return truthy if successful.
Constructor Details
#initialize(key, value) ⇒ PredicateSplitter
Returns a new instance of PredicateSplitter.
11 12 13 |
# File 'lib/philtre/predicate_splitter.rb', line 11 def initialize( key, value ) @key, @value = key, value end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
15 16 17 |
# File 'lib/philtre/predicate_splitter.rb', line 15 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
15 16 17 |
# File 'lib/philtre/predicate_splitter.rb', line 15 def value @value end |
Instance Method Details
#field ⇒ Object
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.
31 32 33 |
# File 'lib/philtre/predicate_splitter.rb', line 31 def field (@field || @key).andand.to_sym end |
#op ⇒ Object
the operator, or predicate
36 37 38 |
# File 'lib/philtre/predicate_splitter.rb', line 36 def op @op.andand.to_sym end |
#split_key(suffix) ⇒ Object Also known as: ===, =~
split suffix from the key and store the two values as name and op return truthy if successful
19 20 21 22 23 |
# File 'lib/philtre/predicate_splitter.rb', line 19 def split_key( suffix ) rv = @key =~ /\A(?:(.*?)_)?(#{suffix})\z/ @field, @op = $1, $2 rv end |