Class: Trailblazer::Finder::Utils::Splitter

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/finder/utils/splitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/trailblazer/finder/utils/splitter.rb', line 8

def key
  @key
end

#valueObject (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

#fieldObject

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

#predicateObject

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