Class: CraftingTable::Search::ItemIDSearch
- Inherits:
-
Object
- Object
- CraftingTable::Search::ItemIDSearch
- Defined in:
- lib/crafting_table/search/item_id_search.rb
Overview
A class which allows to filter recipes and items by their item ID.
Instance Attribute Summary collapse
- #item_id ⇒ Object readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eq?)
Compare two searches for equality.
-
#apply_to(items) ⇒ Array<Item>
Apply this filter to a collection of items.
-
#initialize(item_id) ⇒ ItemIDSearch
constructor
Create a new ItemIDSearch.
Constructor Details
#initialize(item_id) ⇒ ItemIDSearch
Create a new ItemIDSearch
17 18 19 |
# File 'lib/crafting_table/search/item_id_search.rb', line 17 def initialize(item_id) @item_id = item_id end |
Instance Attribute Details
#item_id ⇒ Object (readonly)
12 13 14 |
# File 'lib/crafting_table/search/item_id_search.rb', line 12 def item_id @item_id end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eq?
Compare two searches for equality.
They are considered equal if the item ID for which they filter is equal.
41 42 43 |
# File 'lib/crafting_table/search/item_id_search.rb', line 41 def ==(other) other.item_id == item_id end |
#apply_to(items) ⇒ Array<Item>
Apply this filter to a collection of items.
27 28 29 30 31 32 33 |
# File 'lib/crafting_table/search/item_id_search.rb', line 27 def apply_to(items) if item_id.respond_to?(:include?) items.select { |item| item_id.include? item.item_id } else items.select { |item| item_id == item.item_id } end end |