Class: SearchCriteria
- Inherits:
-
Object
- Object
- SearchCriteria
- Defined in:
- lib/domain/search_criteria/model.rb
Defined Under Namespace
Classes: Filter
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#match ⇒ Object
Returns the value of attribute match.
Class Method Summary collapse
-
.from_json(data) ⇒ Object
Class method to create SearchCriteria from a JSON string.
Instance Method Summary collapse
-
#add_filter(filter) ⇒ Object
Method to add a filter to the search criteria.
-
#initialize(filters: [], match: 'all') ⇒ SearchCriteria
constructor
A new instance of SearchCriteria.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(filters: [], match: 'all') ⇒ SearchCriteria
Returns a new instance of SearchCriteria.
8 9 10 11 |
# File 'lib/domain/search_criteria/model.rb', line 8 def initialize(filters: [], match: 'all') @filters = filters @match = match end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
6 7 8 |
# File 'lib/domain/search_criteria/model.rb', line 6 def filters @filters end |
#match ⇒ Object
Returns the value of attribute match.
6 7 8 |
# File 'lib/domain/search_criteria/model.rb', line 6 def match @match end |
Class Method Details
.from_json(data) ⇒ Object
Class method to create SearchCriteria from a JSON string
66 67 68 69 70 71 72 73 |
# File 'lib/domain/search_criteria/model.rb', line 66 def self.from_json(data) return nil if data.nil? filters = data['filters'].map do |filter_data| Filter.from_json(filter_data) # Utilize Filter.from_json end new(filters:, match: data['match']) end |
Instance Method Details
#add_filter(filter) ⇒ Object
Method to add a filter to the search criteria
61 62 63 |
# File 'lib/domain/search_criteria/model.rb', line 61 def add_filter(filter) @filters << name end |
#to_json(*_args) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/domain/search_criteria/model.rb', line 75 def to_json(*_args) { match: @match, filters: @filters.map(&:to_json) } end |