Class: CraftingTable::Search::FuzzyNameSearch

Inherits:
NameSearch
  • Object
show all
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”.

Author:

Since:

  • 0.3

Instance Attribute Summary

Attributes inherited from NameSearch

#case_sensitive, #name

Instance Method Summary collapse

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.

Parameters:

  • collection (Array<Item, Recipe>)

    Collection of items and recipes which to filter.

Returns:

  • (Array<Item, Recipe>)

    Items and recipes which matched the search criteria.

Since:

  • 0.3



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

Returns:

  • (Boolean)

Since:

  • 0.3



17
18
19
# File 'lib/crafting_table/search/fuzzy_name_search.rb', line 17

def exact?
  false
end