Class: Searchmatcher
- Inherits:
-
Object
- Object
- Searchmatcher
- Defined in:
- lib/searchmatcher.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #formater ⇒ Object
-
#initialize(klass, options) ⇒ Searchmatcher
constructor
A new instance of Searchmatcher.
- #results ⇒ Object
Constructor Details
#initialize(klass, options) ⇒ Searchmatcher
Returns a new instance of Searchmatcher.
2 3 4 5 6 |
# File 'lib/searchmatcher.rb', line 2 def initialize(klass, ) @field = .keys.first.to_s @value = .values.first @klass = klass end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
17 18 19 |
# File 'lib/searchmatcher.rb', line 17 def field @field end |
#klass ⇒ Object
Returns the value of attribute klass.
17 18 19 |
# File 'lib/searchmatcher.rb', line 17 def klass @klass end |
#value ⇒ Object
Returns the value of attribute value.
17 18 19 |
# File 'lib/searchmatcher.rb', line 17 def value @value end |
Instance Method Details
#formater ⇒ Object
12 13 14 15 |
# File 'lib/searchmatcher.rb', line 12 def formater return {} if field.nil? || field.blank? field.split("_or_").map { |f| f + " LIKE :search" }.join(" OR ") end |
#results ⇒ Object
8 9 10 |
# File 'lib/searchmatcher.rb', line 8 def results klass.where(formater, search: "#{value}%") end |