Class: Trailblazer::Finder::Utils::Splitter
- Inherits:
-
Object
- Object
- Trailblazer::Finder::Utils::Splitter
- Defined in:
- lib/trailblazer/finder/utils/splitter.rb
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) ⇒ Splitter
constructor
A new instance of Splitter.
-
#predicate ⇒ Object
the 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) ⇒ Splitter
Returns a new instance of Splitter.
10 11 12 13 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 10 def initialize(key, value) @key = key @value = value.to_s end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 8 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 8 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.
30 31 32 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 30 def field (@field || @key) end |
#predicate ⇒ Object
the predicate
35 36 37 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 35 def predicate @predicate.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
17 18 19 20 21 22 |
# File 'lib/trailblazer/finder/utils/splitter.rb', line 17 def split_key(suffix) rv = @key =~ /\A(?:(.*?)_)?(#{suffix})\z/ @field = Regexp.last_match(1) @predicate = Regexp.last_match(2) !rv.nil? end |