Class: SearchableBy::Column
- Inherits:
-
Object
- Object
- SearchableBy::Column
- Defined in:
- lib/searchable_by/column.rb
Constant Summary collapse
- VALID_MATCH_TYPES =
%i[all prefix exact].freeze
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#match_phrase ⇒ Object
readonly
Returns the value of attribute match_phrase.
-
#node ⇒ Object
Returns the value of attribute node.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#wildcard ⇒ Object
readonly
Returns the value of attribute wildcard.
Instance Method Summary collapse
- #build_condition(value) ⇒ Object
-
#initialize(attr, type: :string, match: :all, match_phrase: nil, wildcard: nil) ⇒ Column
constructor
A new instance of Column.
Constructor Details
#initialize(attr, type: :string, match: :all, match_phrase: nil, wildcard: nil) ⇒ Column
Returns a new instance of Column.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/searchable_by/column.rb', line 8 def initialize(attr, type: :string, match: :all, match_phrase: nil, wildcard: nil) @attr = attr @type = type.to_sym @match = match @match_phrase = match_phrase || match @wildcard = wildcard raise ArgumentError, "invalid match option #{@match.inspect}" unless VALID_MATCH_TYPES.include? @match raise ArgumentError, "invalid match_phrase option #{@match_phrase.inspect}" unless VALID_MATCH_TYPES.include? @match_phrase end |
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
5 6 7 |
# File 'lib/searchable_by/column.rb', line 5 def attr @attr end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
5 6 7 |
# File 'lib/searchable_by/column.rb', line 5 def match @match end |
#match_phrase ⇒ Object (readonly)
Returns the value of attribute match_phrase.
5 6 7 |
# File 'lib/searchable_by/column.rb', line 5 def match_phrase @match_phrase end |
#node ⇒ Object
Returns the value of attribute node.
6 7 8 |
# File 'lib/searchable_by/column.rb', line 6 def node @node end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/searchable_by/column.rb', line 5 def type @type end |
#wildcard ⇒ Object (readonly)
Returns the value of attribute wildcard.
5 6 7 |
# File 'lib/searchable_by/column.rb', line 5 def wildcard @wildcard end |
Instance Method Details
#build_condition(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/searchable_by/column.rb', line 19 def build_condition(value) scope = node.not_eq(nil) case type when :int, :integer int_condition(scope, value) else str_condition(scope, value) end end |