Sha256: 18ba2d52893c5971725e219c0de13c77312bb005ad3ffff69b8d5f3b779834e2
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
require 'fastandand' module Philtre # 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). class PredicateSplitter def initialize( key, value ) @key, @value = key, value end attr_reader :key, :value # split suffix from the key and store the two values as name and op # return truthy if successful def split_key( suffix ) rv = @key =~ /\A(?:(.*?)_)?(#{suffix})\z/ @field, @op = $1, $2 rv end alias_method :===, :split_key alias_method :=~, :split_key # 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. def field (@field || @key).andand.to_sym end # the operator, or predicate def op @op.andand.to_sym end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
philtre-0.1.2 | lib/philtre/predicate_splitter.rb |
philtre-0.1.1 | lib/philtre/predicate_splitter.rb |