Class: CraftingTable::Search::FuzzyNameSearch
- Inherits:
-
NameSearch
- Object
- NameSearch
- CraftingTable::Search::FuzzyNameSearch
- Defined in:
- lib/crafting_table/search/fuzzy_name_search.rb
Overview
A class which allows to filter recipes and items by their name.
Unlike NameSearch, this class does not filter for exact matches, but for inclusions. E.g. searching for “Ore” will return “Iron Ore” as well as “Gold Ore”.
Instance Attribute Summary
Attributes inherited from NameSearch
Instance Method Summary collapse
-
#apply_to(collection) ⇒ Array<Item, Recipe>
Apply this filter to a collection of items or recipes.
- #exact? ⇒ Boolean
Methods inherited from NameSearch
#==, #case_sensitive?, #initialize
Constructor Details
This class inherits a constructor from CraftingTable::Search::NameSearch
Instance Method Details
#apply_to(collection) ⇒ Array<Item, Recipe>
Apply this filter to a collection of items or recipes.
27 28 29 30 31 32 33 |
# File 'lib/crafting_table/search/fuzzy_name_search.rb', line 27 def apply_to(collection) if case_sensitive? collection.select { |item| item.name.include? name } else collection.select { |item| item.name.downcase.include? name.downcase } end end |
#exact? ⇒ Boolean
17 18 19 |
# File 'lib/crafting_table/search/fuzzy_name_search.rb', line 17 def exact? false end |