Class: CraftingTable::Search::InputSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/crafting_table/search/input_search.rb

Overview

A class which allows to filter recipes by their input.

Author:

Since:

  • 0.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ InputSearch

Create a new InputSearch

Parameters:

  • item (Item)

    Item for which to filter.

Since:

  • 0.3



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

def initialize(item)
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Since:

  • 0.3



12
13
14
# File 'lib/crafting_table/search/input_search.rb', line 12

def item
  @item
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eq?

Compare two searches for equality.

They are considered equal if the item for which they filter is equal.

Parameters:

  • other (InputSearch)

    InputSearch which to compare for equality.

Returns:

  • (Boolean)

    Whether two searches are equal.

Since:

  • 0.3



37
38
39
# File 'lib/crafting_table/search/input_search.rb', line 37

def ==(other)
  other.item == item
end

#apply_to(recipes) ⇒ Array<Recipe>

Apply this filter to a collection of recipes.

Parameters:

  • recipes (Array<Recipe>)

    Collection of recipes which to filter.

Returns:

  • (Array<Recipe>)

    Recipes which matched the search criteria

Since:

  • 0.3



27
28
29
# File 'lib/crafting_table/search/input_search.rb', line 27

def apply_to(recipes)
  recipes.select { |recipe| recipe.input.include? item }
end